From c7864643812645ecfb560154bcb1e758555126de Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 2 Apr 2019 23:49:32 -0700 Subject: Adding forum / community pages - Adding main forum page. Fixes #11 - Adding view version for posts. #21 - Got rid of fedi user ids. Fixes #22 - Post sorting working. Fixes #24 --- ui/src/components/post.tsx | 67 +++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 39 deletions(-) (limited to 'ui/src/components/post.tsx') diff --git a/ui/src/components/post.tsx b/ui/src/components/post.tsx index adcc8616..914eebb5 100644 --- a/ui/src/components/post.tsx +++ b/ui/src/components/post.tsx @@ -1,10 +1,11 @@ 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 as CommentFormI, CommentResponse, CommentLikeForm, CreateCommentLikeResponse, CommentSortType } from '../interfaces'; +import { UserOperation, Community, Post as PostI, PostResponse, Comment, CommentForm as CommentFormI, CommentResponse, CommentLikeForm, CreateCommentLikeResponse, CommentSortType, CreatePostLikeResponse } from '../interfaces'; import { WebSocketService, UserService } from '../services'; import { msgOp, hotRank,mdToHtml } from '../utils'; import { MomentTime } from './moment-time'; +import { PostListing } from './post-listing'; import * as autosize from 'autosize'; interface CommentNodeI { @@ -22,13 +23,7 @@ export class Post extends Component { private subscription: Subscription; private emptyState: State = { - post: { - name: null, - attributed_to: null, - community_id: null, - id: null, - published: null, - }, + post: null, comments: [], commentSort: CommentSortType.Hot } @@ -38,7 +33,7 @@ export class Post extends Component { this.state = this.emptyState; - this.state.post.id = Number(this.props.match.params.id); + let postId = Number(this.props.match.params.id); this.subscription = WebSocketService.Instance.subject .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10)))) @@ -48,7 +43,7 @@ export class Post extends Component { () => console.log('complete') ); - WebSocketService.Instance.getPost(this.state.post.id); + WebSocketService.Instance.getPost(postId); } componentWillUnmount() { @@ -62,36 +57,23 @@ export class Post extends Component { render() { return (
-
-
- {this.postHeader()} - - {this.sortRadios()} - {this.commentsTree()} -
-
- {this.newComments()} -
-
- {this.sidebar()} + {this.state.post && +
+
+ +
+ + {this.sortRadios()} + {this.commentsTree()} +
+
+ {this.state.comments.length > 0 && this.newComments()} +
+
+ {this.sidebar()} +
-
-
- ) - } - - postHeader() { - let title = this.state.post.url - ?
- {this.state.post.name} - {(new URL(this.state.post.url)).hostname} -
- :
{this.state.post.name}
; - return ( -
-
{title}
-
via {this.state.post.attributed_to}
-
{this.state.post.body}
+ }
) } @@ -223,6 +205,13 @@ export class Post extends Component { if (res.comment.my_vote !== null) found.my_vote = res.comment.my_vote; this.setState(this.state); + } else if (op == UserOperation.CreatePostLike) { + let res: CreatePostLikeResponse = msg; + this.state.post.my_vote = res.post.my_vote; + this.state.post.score = res.post.score; + this.state.post.upvotes = res.post.upvotes; + this.state.post.downvotes = res.post.downvotes; + this.setState(this.state); } } -- cgit v1.2.3