summaryrefslogtreecommitdiffstats
path: root/ui/src/components/post.tsx
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2019-08-21 22:17:15 -0700
committerDessalines <tyhou13@gmx.com>2019-08-21 22:17:15 -0700
commitb7e73a5559d05a8d06ef2e01f7382a90bb50f44f (patch)
treea12dfa7ed899170e022ec98f3b7f66675de0d9b2 /ui/src/components/post.tsx
parent512cde82ef4950bb0990adfea4f8b9657a2fe356 (diff)
View where a URL has been cross-posted to in the past
- This shows when creating a post, or when viewing a post. - Fixes #131
Diffstat (limited to 'ui/src/components/post.tsx')
-rw-r--r--ui/src/components/post.tsx29
1 files changed, 27 insertions, 2 deletions
diff --git a/ui/src/components/post.tsx b/ui/src/components/post.tsx
index b0204d38..97a9cd72 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, GetPostResponse, PostResponse, Comment, CommentForm as CommentFormI, CommentResponse, CommentSortType, CreatePostLikeResponse, CommunityUser, CommunityResponse, CommentNode as CommentNodeI, BanFromCommunityResponse, BanUserResponse, AddModToCommunityResponse, AddAdminResponse, UserView } from '../interfaces';
+import { UserOperation, Community, Post as PostI, GetPostResponse, PostResponse, Comment, CommentForm as CommentFormI, CommentResponse, CommentSortType, CreatePostLikeResponse, CommunityUser, CommunityResponse, CommentNode as CommentNodeI, BanFromCommunityResponse, BanUserResponse, AddModToCommunityResponse, AddAdminResponse, UserView, SearchType, SortType, SearchForm, SearchResponse } from '../interfaces';
import { WebSocketService, UserService } from '../services';
import { msgOp, hotRank } from '../utils';
import { PostListing } from './post-listing';
+import { PostListings } from './post-listings';
import { Sidebar } from './sidebar';
import { CommentForm } from './comment-form';
import { CommentNodes } from './comment-nodes';
@@ -22,6 +23,7 @@ interface PostState {
scrolled?: boolean;
scrolled_comment_id?: number;
loading: boolean;
+ crossPosts: Array<PostI>;
}
export class Post extends Component<any, PostState> {
@@ -35,7 +37,8 @@ export class Post extends Component<any, PostState> {
moderators: [],
admins: [],
scrolled: false,
- loading: true
+ loading: true,
+ crossPosts: [],
}
constructor(props: any, context: any) {
@@ -112,6 +115,12 @@ export class Post extends Component<any, PostState> {
moderators={this.state.moderators}
admins={this.state.admins}
/>
+ {this.state.crossPosts.length > 0 &&
+ <>
+ <div class="my-1 text-muted small font-weight-bold"><T i18nKey="cross_posts">#</T></div>
+ <PostListings showCommunity posts={this.state.crossPosts} />
+ </>
+ }
<div className="mb-2" />
<CommentForm postId={this.state.post.id} disabled={this.state.post.locked} />
{this.sortRadios()}
@@ -256,6 +265,18 @@ export class Post extends Component<any, PostState> {
this.state.admins = res.admins;
this.state.loading = false;
document.title = `${this.state.post.name} - ${WebSocketService.Instance.site.name}`;
+
+ // Get cross-posts
+ let form: SearchForm = {
+ q: res.post.url,
+ type_: SearchType[SearchType.Url],
+ sort: SortType[SortType.TopAll],
+ page: 1,
+ limit: 6,
+ };
+
+ WebSocketService.Instance.search(form);
+
this.setState(this.state);
} else if (op == UserOperation.CreateComment) {
let res: CommentResponse = msg;
@@ -332,6 +353,10 @@ export class Post extends Component<any, PostState> {
let res: AddAdminResponse = msg;
this.state.admins = res.admins;
this.setState(this.state);
+ } else if (op == UserOperation.Search) {
+ let res: SearchResponse = msg;
+ this.state.crossPosts = res.posts.filter(p => p.id != this.state.post.id);
+ this.setState(this.state);
}
}