Go to list page if deleting with empty history (#6203)

This commit is contained in:
WithoutPants
2025-10-29 11:12:25 +11:00
committed by GitHub
parent 648875995c
commit 1dccecc39c
8 changed files with 25 additions and 7 deletions

View File

@@ -43,6 +43,7 @@ import cx from "classnames";
import { useRatingKeybinds } from "src/hooks/keybinds";
import { ConfigurationContext } from "src/hooks/Config";
import { TruncatedText } from "src/components/Shared/TruncatedText";
import { goBackOrReplace } from "src/utils/history";
interface IProps {
gallery: GQL.GalleryDataFragment;
@@ -167,7 +168,7 @@ export const GalleryPage: React.FC<IProps> = ({ gallery, add }) => {
function onDeleteDialogClosed(deleted: boolean) {
setIsDeleteAlertOpen(false);
if (deleted) {
history.goBack();
goBackOrReplace(history, "/galleries");
}
}

View File

@@ -43,6 +43,7 @@ import { Button, Tab, Tabs } from "react-bootstrap";
import { GroupSubGroupsPanel } from "./GroupSubGroupsPanel";
import { GroupPerformersPanel } from "./GroupPerformersPanel";
import { Icon } from "src/components/Shared/Icon";
import { goBackOrReplace } from "src/utils/history";
const validTabs = ["default", "scenes", "performers", "subgroups"] as const;
type TabKey = (typeof validTabs)[number];
@@ -276,7 +277,7 @@ const GroupPage: React.FC<IProps> = ({ group, tabKey }) => {
return;
}
history.goBack();
goBackOrReplace(history, "/groups");
}
function toggleEditing(value?: boolean) {

View File

@@ -34,6 +34,7 @@ import TextUtils from "src/utils/text";
import { RatingSystem } from "src/components/Shared/Rating/RatingSystem";
import cx from "classnames";
import { TruncatedText } from "src/components/Shared/TruncatedText";
import { goBackOrReplace } from "src/utils/history";
interface IProps {
image: GQL.ImageDataFragment;
@@ -156,7 +157,7 @@ const ImagePage: React.FC<IProps> = ({ image }) => {
function onDeleteDialogClosed(deleted: boolean) {
setIsDeleteAlertOpen(false);
if (deleted) {
history.goBack();
goBackOrReplace(history, "/images");
}
}

View File

@@ -47,6 +47,7 @@ import { HeaderImage } from "src/components/Shared/DetailsPage/HeaderImage";
import { LightboxLink } from "src/hooks/Lightbox/LightboxLink";
import { PatchComponent } from "src/patch";
import { ILightboxImage } from "src/hooks/Lightbox/types";
import { goBackOrReplace } from "src/utils/history";
interface IProps {
performer: GQL.PerformerDataFragment;
@@ -330,7 +331,7 @@ const PerformerPage: React.FC<IProps> = PatchComponent(
return;
}
history.goBack();
goBackOrReplace(history, "/performers");
}
function toggleEditing(value?: boolean) {

View File

@@ -51,6 +51,7 @@ import { lazyComponent } from "src/utils/lazyComponent";
import cx from "classnames";
import { TruncatedText } from "src/components/Shared/TruncatedText";
import { PatchComponent, PatchContainerComponent } from "src/patch";
import { goBackOrReplace } from "src/utils/history";
const SubmitStashBoxDraft = lazyComponent(
() => import("src/components/Dialogs/SubmitDraft")
@@ -909,7 +910,7 @@ const SceneLoader: React.FC<RouteComponentProps<ISceneParams>> = ({
) {
loadScene(queueScenes[currentQueueIndex + 1].id);
} else {
history.goBack();
goBackOrReplace(history, "/scenes");
}
}

View File

@@ -47,6 +47,7 @@ import { FavoriteIcon } from "src/components/Shared/FavoriteIcon";
import { ExternalLinkButtons } from "src/components/Shared/ExternalLinksButton";
import { AliasList } from "src/components/Shared/DetailsPage/AliasList";
import { HeaderImage } from "src/components/Shared/DetailsPage/HeaderImage";
import { goBackOrReplace } from "src/utils/history";
interface IProps {
studio: GQL.StudioDataFragment;
@@ -378,7 +379,7 @@ const StudioPage: React.FC<IProps> = ({ studio, tabKey }) => {
return;
}
history.goBack();
goBackOrReplace(history, "/studios");
}
function renderDeleteAlert() {

View File

@@ -49,6 +49,7 @@ import { ExpandCollapseButton } from "src/components/Shared/CollapseButton";
import { FavoriteIcon } from "src/components/Shared/FavoriteIcon";
import { AliasList } from "src/components/Shared/DetailsPage/AliasList";
import { HeaderImage } from "src/components/Shared/DetailsPage/HeaderImage";
import { goBackOrReplace } from "src/utils/history";
interface IProps {
tag: GQL.TagDataFragment;
@@ -420,7 +421,7 @@ const TagPage: React.FC<IProps> = ({ tag, tabKey }) => {
return;
}
history.goBack();
goBackOrReplace(history, "/tags");
}
function renderDeleteAlert() {

View File

@@ -0,0 +1,11 @@
import { useHistory } from "react-router-dom";
type History = ReturnType<typeof useHistory>;
export function goBackOrReplace(history: History, defaultPath: string) {
if (history.length > 1) {
history.goBack();
} else {
history.replace(defaultPath);
}
}