Fix prompt navigation bug
This commit is contained in:
parent
8ee02da559
commit
e6bbe7280a
2 changed files with 12 additions and 12 deletions
|
@ -129,7 +129,8 @@ export class MarkdownTextArea extends Component<
|
||||||
return (
|
return (
|
||||||
<form id={this.formId} onSubmit={linkEvent(this, this.handleSubmit)}>
|
<form id={this.formId} onSubmit={linkEvent(this, this.handleSubmit)}>
|
||||||
<NavigationPrompt
|
<NavigationPrompt
|
||||||
when={!this.props.hideNavigationWarnings && !!this.state.content}
|
when={!!this.state.content}
|
||||||
|
suppress={this.props.hideNavigationWarnings}
|
||||||
/>
|
/>
|
||||||
<div className="form-group row">
|
<div className="form-group row">
|
||||||
<div className={`col-sm-12`}>
|
<div className={`col-sm-12`}>
|
||||||
|
|
|
@ -4,11 +4,11 @@ import { HistoryService } from "../../services/HistoryService";
|
||||||
|
|
||||||
interface NavigationPromptProps {
|
interface NavigationPromptProps {
|
||||||
when: boolean;
|
when: boolean;
|
||||||
|
suppress?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface NavigationPromptState {
|
interface NavigationPromptState {
|
||||||
promptState: "hidden" | "show" | "approved";
|
promptState: "hidden" | "show" | "approved";
|
||||||
calls: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class NavigationPrompt extends Component<
|
export default class NavigationPrompt extends Component<
|
||||||
|
@ -17,7 +17,6 @@ export default class NavigationPrompt extends Component<
|
||||||
> {
|
> {
|
||||||
state: NavigationPromptState = {
|
state: NavigationPromptState = {
|
||||||
promptState: "hidden",
|
promptState: "hidden",
|
||||||
calls: 0,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(props: NavigationPromptProps, context: any) {
|
constructor(props: NavigationPromptProps, context: any) {
|
||||||
|
@ -25,16 +24,16 @@ export default class NavigationPrompt extends Component<
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount(): void {
|
componentDidMount(): void {
|
||||||
console.log("mounted");
|
if (!this.props.suppress) {
|
||||||
const unblock = HistoryService.history.block(tx => {
|
const unblock = HistoryService.history.block(tx => {
|
||||||
this.setState(prev => ({ ...prev, calls: prev.calls + 1 }));
|
|
||||||
if (!this.props.when || window.confirm(i18n.t("block_leaving"))) {
|
if (!this.props.when || window.confirm(i18n.t("block_leaving"))) {
|
||||||
console.log("Not blocked");
|
|
||||||
console.log(this.state.calls);
|
|
||||||
unblock();
|
unblock();
|
||||||
|
|
||||||
|
tx.retry();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
componentWillUnmount(): void {
|
componentWillUnmount(): void {
|
||||||
console.log("unmounted");
|
console.log("unmounted");
|
||||||
|
|
Loading…
Reference in a new issue