mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 12:54:38 +03:00
Don't prompt for unsaved changes when navigating within main page (#3805)
* Don't prompt for changes when navigating in gallery * Generalise and apply to tags, studios, movies
This commit is contained in:
@@ -38,6 +38,7 @@ import { useRatingKeybinds } from "src/hooks/keybinds";
|
|||||||
import { ConfigurationContext } from "src/hooks/Config";
|
import { ConfigurationContext } from "src/hooks/Config";
|
||||||
import isEqual from "lodash-es/isEqual";
|
import isEqual from "lodash-es/isEqual";
|
||||||
import { DateInput } from "src/components/Shared/DateInput";
|
import { DateInput } from "src/components/Shared/DateInput";
|
||||||
|
import { handleUnsavedChanges } from "src/utils/navigation";
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
gallery: Partial<GQL.GalleryDataFragment>;
|
gallery: Partial<GQL.GalleryDataFragment>;
|
||||||
@@ -370,7 +371,7 @@ export const GalleryEditPanel: React.FC<IProps> = ({
|
|||||||
<div id="gallery-edit-details">
|
<div id="gallery-edit-details">
|
||||||
<Prompt
|
<Prompt
|
||||||
when={formik.dirty}
|
when={formik.dirty}
|
||||||
message={intl.formatMessage({ id: "dialogs.unsaved_changes" })}
|
message={handleUnsavedChanges(intl, "galleries", gallery?.id)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{maybeRenderScrapeDialog()}
|
{maybeRenderScrapeDialog()}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import { useRatingKeybinds } from "src/hooks/keybinds";
|
|||||||
import { ConfigurationContext } from "src/hooks/Config";
|
import { ConfigurationContext } from "src/hooks/Config";
|
||||||
import isEqual from "lodash-es/isEqual";
|
import isEqual from "lodash-es/isEqual";
|
||||||
import { DateInput } from "src/components/Shared/DateInput";
|
import { DateInput } from "src/components/Shared/DateInput";
|
||||||
|
import { handleUnsavedChanges } from "src/utils/navigation";
|
||||||
|
|
||||||
interface IMovieEditPanel {
|
interface IMovieEditPanel {
|
||||||
movie: Partial<GQL.MovieDataFragment>;
|
movie: Partial<GQL.MovieDataFragment>;
|
||||||
@@ -382,7 +383,8 @@ export const MovieEditPanel: React.FC<IMovieEditPanel> = ({
|
|||||||
// Check if it's a redirect after movie creation
|
// Check if it's a redirect after movie creation
|
||||||
if (action === "PUSH" && location.pathname.startsWith("/movies/"))
|
if (action === "PUSH" && location.pathname.startsWith("/movies/"))
|
||||||
return true;
|
return true;
|
||||||
return intl.formatMessage({ id: "dialogs.unsaved_changes" });
|
|
||||||
|
return handleUnsavedChanges(intl, "movies", movie.id)(location);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { useRatingKeybinds } from "src/hooks/keybinds";
|
|||||||
import { ConfigurationContext } from "src/hooks/Config";
|
import { ConfigurationContext } from "src/hooks/Config";
|
||||||
import isEqual from "lodash-es/isEqual";
|
import isEqual from "lodash-es/isEqual";
|
||||||
import { useToast } from "src/hooks/Toast";
|
import { useToast } from "src/hooks/Toast";
|
||||||
|
import { handleUnsavedChanges } from "src/utils/navigation";
|
||||||
|
|
||||||
interface IStudioEditPanel {
|
interface IStudioEditPanel {
|
||||||
studio: Partial<GQL.StudioDataFragment>;
|
studio: Partial<GQL.StudioDataFragment>;
|
||||||
@@ -227,7 +228,8 @@ export const StudioEditPanel: React.FC<IStudioEditPanel> = ({
|
|||||||
// Check if it's a redirect after studio creation
|
// Check if it's a redirect after studio creation
|
||||||
if (action === "PUSH" && location.pathname.startsWith("/studios/"))
|
if (action === "PUSH" && location.pathname.startsWith("/studios/"))
|
||||||
return true;
|
return true;
|
||||||
return intl.formatMessage({ id: "dialogs.unsaved_changes" });
|
|
||||||
|
return handleUnsavedChanges(intl, "studios", studio.id)(location);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { LoadingIndicator } from "src/components/Shared/LoadingIndicator";
|
|||||||
import { StringListInput } from "src/components/Shared/StringListInput";
|
import { StringListInput } from "src/components/Shared/StringListInput";
|
||||||
import isEqual from "lodash-es/isEqual";
|
import isEqual from "lodash-es/isEqual";
|
||||||
import { useToast } from "src/hooks/Toast";
|
import { useToast } from "src/hooks/Toast";
|
||||||
|
import { handleUnsavedChanges } from "src/utils/navigation";
|
||||||
|
|
||||||
interface ITagEditPanel {
|
interface ITagEditPanel {
|
||||||
tag: Partial<GQL.TagDataFragment>;
|
tag: Partial<GQL.TagDataFragment>;
|
||||||
@@ -161,11 +162,12 @@ export const TagEditPanel: React.FC<ITagEditPanel> = ({
|
|||||||
<Prompt
|
<Prompt
|
||||||
when={formik.dirty}
|
when={formik.dirty}
|
||||||
message={(location, action) => {
|
message={(location, action) => {
|
||||||
// Check if it's a redirect after movie creation
|
// Check if it's a redirect after tag creation
|
||||||
if (action === "PUSH" && location.pathname.startsWith("/tags/")) {
|
if (action === "PUSH" && location.pathname.startsWith("/tags/")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return intl.formatMessage({ id: "dialogs.unsaved_changes" });
|
|
||||||
|
return handleUnsavedChanges(intl, "tags", tag.id)(location);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
import { GalleriesCriterion } from "src/models/list-filter/criteria/galleries";
|
import { GalleriesCriterion } from "src/models/list-filter/criteria/galleries";
|
||||||
import { PhashCriterion } from "src/models/list-filter/criteria/phash";
|
import { PhashCriterion } from "src/models/list-filter/criteria/phash";
|
||||||
import { ILabeledId } from "src/models/list-filter/types";
|
import { ILabeledId } from "src/models/list-filter/types";
|
||||||
|
import { IntlShape } from "react-intl";
|
||||||
|
|
||||||
function addExtraCriteria(
|
function addExtraCriteria(
|
||||||
dest: Criterion<CriterionValue>[],
|
dest: Criterion<CriterionValue>[],
|
||||||
@@ -346,6 +347,21 @@ const makeGalleryImagesUrl = (
|
|||||||
return `/images?${filter.makeQueryParameters()}`;
|
return `/images?${filter.makeQueryParameters()}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function handleUnsavedChanges(
|
||||||
|
intl: IntlShape,
|
||||||
|
basepath: string,
|
||||||
|
id?: string
|
||||||
|
) {
|
||||||
|
return function (location: { pathname: string }) {
|
||||||
|
// #2291 - don't prompt if we're navigating within the gallery being edited
|
||||||
|
if (id !== undefined && location.pathname === `/${basepath}/${id}`) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return intl.formatMessage({ id: "dialogs.unsaved_changes" });
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const NavUtils = {
|
const NavUtils = {
|
||||||
makePerformerScenesUrl,
|
makePerformerScenesUrl,
|
||||||
makePerformerImagesUrl,
|
makePerformerImagesUrl,
|
||||||
|
|||||||
Reference in New Issue
Block a user