diff options
author | Filip785 <fdjuricic98@gmail.com> | 2020-07-08 22:15:34 +0200 |
---|---|---|
committer | Filip785 <fdjuricic98@gmail.com> | 2020-07-08 22:15:34 +0200 |
commit | abdbd50f5edb03917fc0cd770ad1f9f44f5b8980 (patch) | |
tree | 1309f79fabe87f940d799f5ae3ba580002240526 | |
parent | 8fe8836bc263be11895fafa958409499c9e9fc9d (diff) | |
parent | 32d43b85b942e7b9d12b462a13c3dd52252acc6c (diff) |
Merge remote-tracking branch 'upstream/master' into cake-day
-rw-r--r-- | ui/src/components/comment-form.tsx | 9 | ||||
-rw-r--r-- | ui/src/components/community-form.tsx | 14 | ||||
-rw-r--r-- | ui/src/components/post-form.tsx | 14 | ||||
-rw-r--r-- | ui/src/components/private-message-form.tsx | 9 | ||||
-rw-r--r-- | ui/src/components/site-form.tsx | 16 |
5 files changed, 62 insertions, 0 deletions
diff --git a/ui/src/components/comment-form.tsx b/ui/src/components/comment-form.tsx index 61ee3d77..770c127c 100644 --- a/ui/src/components/comment-form.tsx +++ b/ui/src/components/comment-form.tsx @@ -108,8 +108,17 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> { }); } + componentDidUpdate() { + if (this.state.commentForm.content) { + window.onbeforeunload = () => true; + } else { + window.onbeforeunload = undefined; + } + } + componentWillUnmount() { this.subscription.unsubscribe(); + window.onbeforeunload = null; } render() { diff --git a/ui/src/components/community-form.tsx b/ui/src/components/community-form.tsx index 46d62ef5..95d9c1f7 100644 --- a/ui/src/components/community-form.tsx +++ b/ui/src/components/community-form.tsx @@ -97,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() { diff --git a/ui/src/components/post-form.tsx b/ui/src/components/post-form.tsx index 8c693ac0..a88d38c7 100644 --- a/ui/src/components/post-form.tsx +++ b/ui/src/components/post-form.tsx @@ -151,8 +151,22 @@ export class PostForm extends Component<PostFormProps, PostFormState> { setupTippy(); } + componentDidUpdate() { + if ( + !this.state.loading && + (this.state.postForm.name || + this.state.postForm.url || + this.state.postForm.body) + ) { + window.onbeforeunload = () => true; + } else { + window.onbeforeunload = undefined; + } + } + componentWillUnmount() { this.subscription.unsubscribe(); + window.onbeforeunload = null; } render() { diff --git a/ui/src/components/private-message-form.tsx b/ui/src/components/private-message-form.tsx index 9f7fb32c..6ae7efe7 100644 --- a/ui/src/components/private-message-form.tsx +++ b/ui/src/components/private-message-form.tsx @@ -110,8 +110,17 @@ export class PrivateMessageForm extends Component< setupTippy(); } + componentDidUpdate() { + if (!this.state.loading && this.state.privateMessageForm.content) { + window.onbeforeunload = () => true; + } else { + window.onbeforeunload = undefined; + } + } + componentWillUnmount() { this.subscription.unsubscribe(); + window.onbeforeunload = null; } render() { diff --git a/ui/src/components/site-form.tsx b/ui/src/components/site-form.tsx index a51286c8..291251d3 100644 --- a/ui/src/components/site-form.tsx +++ b/ui/src/components/site-form.tsx @@ -64,6 +64,22 @@ export class SiteForm extends Component<SiteFormProps, SiteFormState> { this.setState(this.state); } + componentDidUpdate() { + if ( + !this.state.loading && + !this.props.site && + (this.state.siteForm.name || this.state.siteForm.description) + ) { + window.onbeforeunload = () => true; + } else { + window.onbeforeunload = undefined; + } + } + + componentWillUnmount() { + window.onbeforeunload = null; + } + render() { return ( <> |