From 25dcb8f4f4f80e401d1d3154923e2dcd05664c76 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 26 Mar 2019 11:00:18 -0700 Subject: Adding a few endpoints. - Adding CreatePost, CreateComment, CreateCommunity --- ui/src/components/post.tsx | 126 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 ui/src/components/post.tsx (limited to 'ui/src/components/post.tsx') diff --git a/ui/src/components/post.tsx b/ui/src/components/post.tsx new file mode 100644 index 00000000..8d84f27a --- /dev/null +++ b/ui/src/components/post.tsx @@ -0,0 +1,126 @@ +import { Component, linkEvent } from 'inferno'; +import { Subscription } from "rxjs"; +import { retryWhen, delay, take } from 'rxjs/operators'; +import { UserOperation, Community, Post as PostI, PostResponse, Comment, CommentForm } from '../interfaces'; +import { WebSocketService, UserService } from '../services'; +import { msgOp } from '../utils'; + +interface State { + post: PostI; + commentForm: CommentForm; + comments: Array; +} + +export class Post extends Component { + + private subscription: Subscription; + private emptyState: State = { + post: { + name: null, + attributed_to: null, + community_id: null, + id: null, + published: null, + }, + commentForm: { + auth: null, + content: null, + post_id: null + }, + comments: [] + } + + constructor(props, context) { + super(props, context); + + let postId = Number(this.props.match.params.id); + + this.state = this.emptyState; + this.state.commentForm.post_id = postId; + + 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') + ); + + WebSocketService.Instance.getPost(postId); + } + + componentWillUnmount() { + this.subscription.unsubscribe(); + } + + render() { + return ( +
+
+
+ {this.state.post.name} + {this.commentForm()} + {this.comments()} +
+
+
+ ) + } + + comments() { + return ( +
+

Comments

+ {this.state.comments.map(comment => +
{comment.content}
+ )} +
+ ) + } + + + commentForm() { + return ( +
+
+

Create Comment

+
+ +
+