import { Component } from "inferno";
import { Provider } from "inferno-i18next-dess";
import { Route, Switch } from "inferno-router";
-import { IsoDataOptionalSite } from "shared/interfaces";
import { i18n } from "../../i18next";
+import { IsoDataOptionalSite } from "../../interfaces";
import { routes } from "../../routes";
import { isAuthPath, setIsoData } from "../../utils";
import AuthGuard from "../common/auth-guard";
wsUserOp,
} from "lemmy-js-client";
import { Subscription } from "rxjs";
-import { CommentNodeI } from "shared/interfaces";
import { i18n } from "../../i18next";
+import { CommentNodeI } from "../../interfaces";
import { UserService, WebSocketService } from "../../services";
import {
capitalizeFirstLetter,
import autosize from "autosize";
import { NoOptionI18nKeys } from "i18next";
import { Component, linkEvent } from "inferno";
-import { Prompt } from "inferno-router";
import { Language } from "lemmy-js-client";
import { i18n } from "../../i18next";
import { UserService } from "../../services";
import { EmojiPicker } from "./emoji-picker";
import { Icon, Spinner } from "./icon";
import { LanguageSelect } from "./language-select";
+import NavigationPrompt from "./navigation-prompt";
import ProgressBar from "./progress-bar";
interface MarkdownTextAreaProps {
return (
<form id={this.formId} onSubmit={linkEvent(this, this.handleSubmit)}>
- <Prompt
- when={!this.props.hideNavigationWarnings && this.state.content}
- message={i18n.t("block_leaving")}
- />
+ <NavigationPrompt when={!!this.state.content} />
<div className="form-group row">
<div className={`col-sm-12`}>
<textarea
--- /dev/null
+import { Component } from "inferno";
+import { i18n } from "../../../shared/i18next";
+
+export interface IPromptProps {
+ when: boolean;
+}
+
+export default class NavigationPrompt extends Component<IPromptProps, any> {
+ public unblock;
+
+ public enable() {
+ if (this.unblock) {
+ this.unblock();
+ }
+
+ this.unblock = this.context.router.history.block(tx => {
+ if (window.confirm(i18n.t("block_leaving"))) {
+ this.unblock();
+ tx.retry();
+ }
+ });
+ }
+
+ public disable() {
+ if (this.unblock) {
+ this.unblock();
+ this.unblock = null;
+ }
+ }
+ public componentWillMount() {
+ if (this.props.when) {
+ this.enable();
+ }
+ }
+
+ public componentWillReceiveProps(nextProps: IPromptProps) {
+ if (nextProps.when) {
+ if (!this.props.when) {
+ this.enable();
+ }
+ } else {
+ this.disable();
+ }
+ }
+
+ public componentWillUnmount() {
+ this.disable();
+ }
+
+ public render() {
+ return null;
+ }
+}
import classNames from "classnames";
-import { ThemeColor } from "shared/utils";
+import { ThemeColor } from "../../utils";
interface ProgressBarProps {
className?: string;
wsUserOp,
} from "lemmy-js-client";
import { Subscription } from "rxjs";
-import { InitialFetchRequest } from "shared/interfaces";
import { i18n } from "../../i18next";
+import { InitialFetchRequest } from "../../interfaces";
import { WebSocketService } from "../../services";
import {
QueryParams,
import { Component, linkEvent } from "inferno";
-import { Prompt } from "inferno-router";
import {
CommunityResponse,
CommunityView,
import { ImageUploadForm } from "../common/image-upload-form";
import { LanguageSelect } from "../common/language-select";
import { MarkdownTextArea } from "../common/markdown-textarea";
+import NavigationPrompt from "../common/navigation-prompt";
interface CommunityFormProps {
community_view?: CommunityView; // If a community is given, that means this is an edit
render() {
return (
<>
- <Prompt
+ <NavigationPrompt
when={
!this.state.loading &&
- (this.state.form.name ||
+ !!(
+ this.state.form.name ||
this.state.form.title ||
- this.state.form.description)
+ this.state.form.description
+ )
}
- message={i18n.t("block_leaving")}
/>
<form onSubmit={linkEvent(this, this.handleCreateCommunitySubmit)}>
{!this.props.community_view && (
InfernoMouseEvent,
linkEvent,
} from "inferno";
-import { Prompt } from "inferno-router";
import {
CreateSite,
EditSite,
import { LanguageSelect } from "../common/language-select";
import { ListingTypeSelect } from "../common/listing-type-select";
import { MarkdownTextArea } from "../common/markdown-textarea";
+import NavigationPrompt from "../common/navigation-prompt";
interface SiteFormProps {
siteRes: GetSiteResponse;
const siteSetup = this.props.siteRes.site_view.local_site.site_setup;
return (
<>
- <Prompt
+ <NavigationPrompt
when={
!this.state.loading &&
!siteSetup &&
- (this.state.siteForm.name ||
+ !!(
+ this.state.siteForm.name ||
this.state.siteForm.sidebar ||
this.state.siteForm.application_question ||
- this.state.siteForm.description)
+ this.state.siteForm.description
+ )
}
- message={i18n.t("block_leaving")}
/>
<form onSubmit={linkEvent(this, this.handleCreateSiteSubmit)}>
<h5>{`${
wsUserOp,
} from "lemmy-js-client";
import { Subscription } from "rxjs";
-import { InitialFetchRequest, PostFormParams } from "shared/interfaces";
import { i18n } from "../../i18next";
+import { InitialFetchRequest, PostFormParams } from "../../interfaces";
import { WebSocketService } from "../../services";
import {
Choice,
import autosize from "autosize";
import { Component, linkEvent } from "inferno";
-import { Prompt } from "inferno-router";
import {
CreatePost,
EditPost,
import { Icon, Spinner } from "../common/icon";
import { LanguageSelect } from "../common/language-select";
import { MarkdownTextArea } from "../common/markdown-textarea";
+import NavigationPrompt from "../common/navigation-prompt";
import { SearchableSelect } from "../common/searchable-select";
import { PostListings } from "./post-listings";
const url = this.state.form.url;
return (
<div>
- <Prompt
+ <NavigationPrompt
when={
!this.state.loading &&
- (this.state.form.name ||
+ !!(
+ this.state.form.name ||
this.state.form.url ||
- this.state.form.body)
+ this.state.form.body
+ )
}
- message={i18n.t("block_leaving")}
/>
<form onSubmit={linkEvent(this, this.handlePostSubmit)}>
<div className="form-group row">
import { Component, linkEvent } from "inferno";
import { T } from "inferno-i18next-dess";
-import { Prompt } from "inferno-router";
import {
CreatePrivateMessage,
EditPrivateMessage,
} from "../../utils";
import { Icon, Spinner } from "../common/icon";
import { MarkdownTextArea } from "../common/markdown-textarea";
+import NavigationPrompt from "../common/navigation-prompt";
import { PersonListing } from "../person/person-listing";
interface PrivateMessageFormProps {
render() {
return (
<div>
- <Prompt
- when={!this.state.loading && this.state.content}
- message={i18n.t("block_leaving")}
- />
+ <NavigationPrompt when={!this.state.loading && !!this.state.content} />
<form onSubmit={linkEvent(this, this.handlePrivateMessageSubmit)}>
{!this.props.privateMessageView && (
<div className="form-group row">