diff options
author | Dessalines <tyhou13@gmx.com> | 2019-03-26 11:00:18 -0700 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2019-03-26 11:00:18 -0700 |
commit | 25dcb8f4f4f80e401d1d3154923e2dcd05664c76 (patch) | |
tree | 85e9644b64e0eb3fa139db18075dbfd73f854a38 /ui/src/components/community.tsx | |
parent | e1cb805cfc719d6266ec50e5f1ef3ac1edf74656 (diff) |
Adding a few endpoints.
- Adding CreatePost, CreateComment, CreateCommunity
Diffstat (limited to 'ui/src/components/community.tsx')
-rw-r--r-- | ui/src/components/community.tsx | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/ui/src/components/community.tsx b/ui/src/components/community.tsx new file mode 100644 index 00000000..b0322635 --- /dev/null +++ b/ui/src/components/community.tsx @@ -0,0 +1,72 @@ +import { Component, linkEvent } from 'inferno'; +import { Subscription } from "rxjs"; +import { retryWhen, delay, take } from 'rxjs/operators'; +import { UserOperation, Community as CommunityI, CommunityResponse, Post } from '../interfaces'; +import { WebSocketService, UserService } from '../services'; +import { msgOp } from '../utils'; + +interface State { + community: CommunityI; + posts: Array<Post>; +} + +export class Community extends Component<any, State> { + + private subscription: Subscription; + private emptyState: State = { + community: { + id: null, + name: null, + published: null + }, + posts: [] + } + + constructor(props, context) { + super(props, context); + + this.state = this.emptyState; + + console.log(this.props.match.params.id); + + this.subscription = WebSocketService.Instance.subject + .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10)))) + .subscribe( + (msg) => this.parseMessage(msg), + (err) => console.error(err), + () => console.log('complete') + ); + + let communityId = Number(this.props.match.params.id); + WebSocketService.Instance.getCommunity(communityId); + } + + componentWillUnmount() { + this.subscription.unsubscribe(); + } + + render() { + return ( + <div class="container"> + <div class="row"> + <div class="col-12 col-lg-6 mb-4"> + {this.state.community.name} + </div> + </div> + </div> + ) + } + + parseMessage(msg: any) { + console.log(msg); + let op: UserOperation = msgOp(msg); + if (msg.error) { + alert(msg.error); + return; + } else if (op == UserOperation.GetCommunity) { + let res: CommunityResponse = msg; + this.state.community = res.community; + this.setState(this.state); + } + } +} |