From 747a8f5b96b10f56f14d7dad30764084e69d8cab Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 3 Jan 2020 13:52:21 -0500 Subject: [PATCH] Fixing create_post, create_community, and login pages. - Includes fetching the site for `enable_nsfw` info. Fixes #400 --- ui/src/components/community-form.tsx | 10 +++++++++- ui/src/components/login.tsx | 20 +++++++++++++------- ui/src/components/post-form.tsx | 10 +++++++++- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/ui/src/components/community-form.tsx b/ui/src/components/community-form.tsx index d5efb432..2085da28 100644 --- a/ui/src/components/community-form.tsx +++ b/ui/src/components/community-form.tsx @@ -7,6 +7,7 @@ import { Category, ListCategoriesResponse, CommunityResponse, + GetSiteResponse, } from '../interfaces'; import { WebSocketService } from '../services'; import { msgOp, capitalizeFirstLetter } from '../utils'; @@ -27,6 +28,7 @@ interface CommunityFormState { communityForm: CommunityFormI; categories: Array; loading: boolean; + enable_nsfw: boolean; } export class CommunityForm extends Component< @@ -44,6 +46,7 @@ export class CommunityForm extends Component< }, categories: [], loading: false, + enable_nsfw: null, }; constructor(props: any, context: any) { @@ -79,6 +82,7 @@ export class CommunityForm extends Component< ); WebSocketService.Instance.listCategories(); + WebSocketService.Instance.getSite(); } componentDidMount() { @@ -157,7 +161,7 @@ export class CommunityForm extends Component< - {WebSocketService.Instance.site.enable_nsfw && ( + {this.state.enable_nsfw && (
@@ -267,6 +271,10 @@ export class CommunityForm extends Component< let res: CommunityResponse = msg; this.state.loading = false; this.props.onEdit(res.community); + } else if (op == UserOperation.GetSite) { + let res: GetSiteResponse = msg; + this.state.enable_nsfw = res.site.enable_nsfw; + this.setState(this.state); } } } diff --git a/ui/src/components/login.tsx b/ui/src/components/login.tsx index c8de6c70..53b7a22f 100644 --- a/ui/src/components/login.tsx +++ b/ui/src/components/login.tsx @@ -7,6 +7,7 @@ import { LoginResponse, UserOperation, PasswordResetForm, + GetSiteResponse, } from '../interfaces'; import { WebSocketService, UserService } from '../services'; import { msgOp, validEmail } from '../utils'; @@ -18,6 +19,7 @@ interface State { registerForm: RegisterForm; loginLoading: boolean; registerLoading: boolean; + enable_nsfw: boolean; } export class Login extends Component { @@ -37,6 +39,7 @@ export class Login extends Component { }, loginLoading: false, registerLoading: false, + enable_nsfw: undefined, }; constructor(props: any, context: any) { @@ -58,18 +61,14 @@ export class Login extends Component { err => console.error(err), () => console.log('complete') ); + + WebSocketService.Instance.getSite(); } componentWillUnmount() { this.subscription.unsubscribe(); } - componentDidMount() { - document.title = `${i18n.t('login')} - ${ - WebSocketService.Instance.site.name - }`; - } - render() { return (
@@ -205,7 +204,7 @@ export class Login extends Component { />
- {WebSocketService.Instance.site.enable_nsfw && ( + {this.state.enable_nsfw && (
@@ -322,6 +321,13 @@ export class Login extends Component { this.props.history.push('/communities'); } else if (op == UserOperation.PasswordReset) { alert(i18n.t('reset_password_mail_sent')); + } else if (op == UserOperation.GetSite) { + let res: GetSiteResponse = msg; + this.state.enable_nsfw = res.site.enable_nsfw; + this.setState(this.state); + document.title = `${i18n.t('login')} - ${ + WebSocketService.Instance.site.name + }`; } } } diff --git a/ui/src/components/post-form.tsx b/ui/src/components/post-form.tsx index ef639c9d..7964a3ff 100644 --- a/ui/src/components/post-form.tsx +++ b/ui/src/components/post-form.tsx @@ -15,6 +15,7 @@ import { SearchForm, SearchType, SearchResponse, + GetSiteResponse, } from '../interfaces'; import { WebSocketService, UserService } from '../services'; import { @@ -49,6 +50,7 @@ interface PostFormState { suggestedTitle: string; suggestedPosts: Array; crossPosts: Array; + enable_nsfw: boolean; } export class PostForm extends Component { @@ -70,6 +72,7 @@ export class PostForm extends Component { suggestedTitle: undefined, suggestedPosts: [], crossPosts: [], + enable_nsfw: undefined, }; constructor(props: any, context: any) { @@ -124,6 +127,7 @@ export class PostForm extends Component { }; WebSocketService.Instance.listCommunities(listCommunitiesForm); + WebSocketService.Instance.getSite(); } componentDidMount() { @@ -287,7 +291,7 @@ export class PostForm extends Component {
)} - {WebSocketService.Instance.site.enable_nsfw && ( + {this.state.enable_nsfw && (
@@ -498,6 +502,10 @@ export class PostForm extends Component { this.state.crossPosts = res.posts; } this.setState(this.state); + } else if (op == UserOperation.GetSite) { + let res: GetSiteResponse = msg; + this.state.enable_nsfw = res.site.enable_nsfw; + this.setState(this.state); } } } -- 2.44.1