diff options
author | Dessalines <tyhou13@gmx.com> | 2020-07-08 14:32:37 -0400 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2020-07-08 14:32:37 -0400 |
commit | 32d43b85b942e7b9d12b462a13c3dd52252acc6c (patch) | |
tree | c166b399e7e790bf07123343659a0c247c14f545 /ui/src/components/site-form.tsx | |
parent | d720993141cd941a5b724b38a675982f793d2f2c (diff) |
Blocking page refresh when forms are filled. Fixes #671
Diffstat (limited to 'ui/src/components/site-form.tsx')
-rw-r--r-- | ui/src/components/site-form.tsx | 16 |
1 files changed, 16 insertions, 0 deletions
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 ( <> |