Fix prompt navigation bug

This commit is contained in:
SleeplessOne1917 2023-06-08 17:55:40 -04:00
parent 8ee02da559
commit e6bbe7280a
2 changed files with 12 additions and 12 deletions

View file

@ -129,7 +129,8 @@ export class MarkdownTextArea extends Component<
return (
<form id={this.formId} onSubmit={linkEvent(this, this.handleSubmit)}>
<NavigationPrompt
when={!this.props.hideNavigationWarnings && !!this.state.content}
when={!!this.state.content}
suppress={this.props.hideNavigationWarnings}
/>
<div className="form-group row">
<div className={`col-sm-12`}>

View file

@ -4,11 +4,11 @@ import { HistoryService } from "../../services/HistoryService";
interface NavigationPromptProps {
when: boolean;
suppress?: boolean;
}
interface NavigationPromptState {
promptState: "hidden" | "show" | "approved";
calls: number;
}
export default class NavigationPrompt extends Component<
@ -17,7 +17,6 @@ export default class NavigationPrompt extends Component<
> {
state: NavigationPromptState = {
promptState: "hidden",
calls: 0,
};
constructor(props: NavigationPromptProps, context: any) {
@ -25,15 +24,15 @@ export default class NavigationPrompt extends Component<
}
componentDidMount(): void {
console.log("mounted");
const unblock = HistoryService.history.block(tx => {
this.setState(prev => ({ ...prev, calls: prev.calls + 1 }));
if (!this.props.when || window.confirm(i18n.t("block_leaving"))) {
console.log("Not blocked");
console.log(this.state.calls);
unblock();
}
});
if (!this.props.suppress) {
const unblock = HistoryService.history.block(tx => {
if (!this.props.when || window.confirm(i18n.t("block_leaving"))) {
unblock();
tx.retry();
}
});
}
}
componentWillUnmount(): void {