diff options
author | Dessalines <tyhou13@gmx.com> | 2020-07-11 19:12:56 -0400 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2020-07-11 19:12:56 -0400 |
commit | 60288b2d060ba930fe6cae22c4824d88fe7a00c9 (patch) | |
tree | 8fed01325853240c69f3688ee621be29bedfd382 /ui/src/components/community-form.tsx | |
parent | 1710844a1bc6a4f46eceaa12f2fb428cb794c694 (diff) | |
parent | 1b9f2fa5f7f7831f59b24cb36a5607a769a0d92e (diff) |
Merge branch 'master' into jmarthernandez-remove-karma-from-search
Diffstat (limited to 'ui/src/components/community-form.tsx')
-rw-r--r-- | ui/src/components/community-form.tsx | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/ui/src/components/community-form.tsx b/ui/src/components/community-form.tsx index 90e12738..95d9c1f7 100644 --- a/ui/src/components/community-form.tsx +++ b/ui/src/components/community-form.tsx @@ -8,7 +8,6 @@ import { Category, ListCategoriesResponse, CommunityResponse, - GetSiteResponse, WebSocketJsonResponse, } from '../interfaces'; import { WebSocketService } from '../services'; @@ -30,13 +29,13 @@ interface CommunityFormProps { onCancel?(): any; onCreate?(community: Community): any; onEdit?(community: Community): any; + enableNsfw: boolean; } interface CommunityFormState { communityForm: CommunityFormI; categories: Array<Category>; loading: boolean; - enable_nsfw: boolean; } export class CommunityForm extends Component< @@ -56,7 +55,6 @@ export class CommunityForm extends Component< }, categories: [], loading: false, - enable_nsfw: null, }; constructor(props: any, context: any) { @@ -86,7 +84,6 @@ export class CommunityForm extends Component< ); WebSocketService.Instance.listCategories(); - WebSocketService.Instance.getSite(); } componentDidMount() { @@ -100,8 +97,22 @@ export class CommunityForm extends Component< }); } + componentDidUpdate() { + if ( + !this.state.loading && + (this.state.communityForm.name || + this.state.communityForm.title || + this.state.communityForm.description) + ) { + window.onbeforeunload = () => true; + } else { + window.onbeforeunload = undefined; + } + } + componentWillUnmount() { this.subscription.unsubscribe(); + window.onbeforeunload = null; } render() { @@ -187,7 +198,7 @@ export class CommunityForm extends Component< </div> </div> - {this.state.enable_nsfw && ( + {this.props.enableNsfw && ( <div class="form-group row"> <div class="col-12"> <div class="form-check"> @@ -303,10 +314,6 @@ export class CommunityForm extends Component< let data = res.data as CommunityResponse; this.state.loading = false; this.props.onEdit(data.community); - } else if (res.op == UserOperation.GetSite) { - let data = res.data as GetSiteResponse; - this.state.enable_nsfw = data.site.enable_nsfw; - this.setState(this.state); } } } |