diff options
author | Dessalines <tyhou13@gmx.com> | 2020-07-08 01:02:14 -0400 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2020-07-08 01:02:14 -0400 |
commit | cd4e0ab3c2cfd615e4771fb9181a31ce237b5ceb (patch) | |
tree | 699dd63cd3ad7601e49a1173884506e3638ae37a /ui/src/components/search.tsx | |
parent | 8fda7d00d5ec9e415b44aa10cff3c4d735563a20 (diff) |
HTML title bugs.
- Fixing HTML titles for some pages. Fixes #801
- Removing WebSocketService.Instance.site, fetching site on demand now.
Diffstat (limited to 'ui/src/components/search.tsx')
-rw-r--r-- | ui/src/components/search.tsx | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/ui/src/components/search.tsx b/ui/src/components/search.tsx index a02f035f..2588528a 100644 --- a/ui/src/components/search.tsx +++ b/ui/src/components/search.tsx @@ -15,6 +15,8 @@ import { PostResponse, CommentResponse, WebSocketJsonResponse, + GetSiteResponse, + Site, } from '../interfaces'; import { WebSocketService } from '../services'; import { @@ -41,6 +43,7 @@ interface SearchState { page: number; searchResponse: SearchResponse; loading: boolean; + site: Site; } export class Search extends Component<any, SearchState> { @@ -58,6 +61,20 @@ export class Search extends Component<any, SearchState> { users: [], }, loading: false, + site: { + id: undefined, + name: undefined, + creator_id: undefined, + published: undefined, + creator_name: undefined, + number_of_users: undefined, + number_of_posts: undefined, + number_of_comments: undefined, + number_of_communities: undefined, + enable_downvotes: undefined, + open_registration: undefined, + enable_nsfw: undefined, + }, }; getSearchQueryFromProps(props: any): string { @@ -94,6 +111,8 @@ export class Search extends Component<any, SearchState> { () => console.log('complete') ); + WebSocketService.Instance.getSite(); + if (this.state.q) { this.search(); } @@ -118,12 +137,6 @@ export class Search extends Component<any, SearchState> { } } - componentDidMount() { - document.title = `${i18n.t('search')} - ${ - WebSocketService.Instance.site.name - }`; - } - render() { return ( <div class="container"> @@ -241,13 +254,19 @@ export class Search extends Component<any, SearchState> { <div class="row"> <div class="col-12"> {i.type_ == 'posts' && ( - <PostListing post={i.data as Post} showCommunity /> + <PostListing + post={i.data as Post} + showCommunity + enableDownvotes={this.state.site.enable_downvotes} + enableNsfw={this.state.site.enable_nsfw} + /> )} {i.type_ == 'comments' && ( <CommentNodes nodes={[{ comment: i.data as Comment }]} locked noIndent + enableDownvotes={this.state.site.enable_downvotes} /> )} {i.type_ == 'communities' && ( @@ -281,6 +300,7 @@ export class Search extends Component<any, SearchState> { nodes={commentsToFlatNodes(this.state.searchResponse.comments)} locked noIndent + enableDownvotes={this.state.site.enable_downvotes} /> ); } @@ -291,7 +311,12 @@ export class Search extends Component<any, SearchState> { {this.state.searchResponse.posts.map(post => ( <div class="row"> <div class="col-12"> - <PostListing post={post} showCommunity /> + <PostListing + post={post} + showCommunity + enableDownvotes={this.state.site.enable_downvotes} + enableNsfw={this.state.site.enable_nsfw} + /> </div> </div> ))} @@ -455,7 +480,7 @@ export class Search extends Component<any, SearchState> { this.state.searchResponse = data; this.state.loading = false; document.title = `${i18n.t('search')} - ${this.state.q} - ${ - WebSocketService.Instance.site.name + this.state.site.name }`; window.scrollTo(0, 0); this.setState(this.state); @@ -467,6 +492,11 @@ export class Search extends Component<any, SearchState> { let data = res.data as PostResponse; createPostLikeFindRes(data, this.state.searchResponse.posts); this.setState(this.state); + } else if (res.op == UserOperation.GetSite) { + let data = res.data as GetSiteResponse; + this.state.site = data.site; + this.setState(this.state); + document.title = `${i18n.t('search')} - ${data.site.name}`; } } } |