diff --git a/ui/v2.5/src/components/Settings/Tasks/LibraryTasks.tsx b/ui/v2.5/src/components/Settings/Tasks/LibraryTasks.tsx index 6bf8924ad..6fd2f2a29 100644 --- a/ui/v2.5/src/components/Settings/Tasks/LibraryTasks.tsx +++ b/ui/v2.5/src/components/Settings/Tasks/LibraryTasks.tsx @@ -8,6 +8,7 @@ import { } from "src/core/StashService"; import { withoutTypename } from "src/utils/data"; import { useConfigurationContext } from "src/hooks/Config"; +import { useAutoTagTrigger } from "src/hooks/useAutoTagTrigger"; import { IdentifyDialog } from "../../Dialogs/IdentifyDialog/IdentifyDialog"; import * as GQL from "src/core/generated-graphql"; import { DirectorySelectionDialog } from "./DirectorySelectionDialog"; @@ -201,13 +202,10 @@ export const LibraryTasks: React.FC = () => { }); } - function onAutoTagClick() { - if (configuration?.interface.disableAutoTagWarning) { - runAutoTag(); - return; - } - setDialogOpen({ autoTagAlert: true }); - } + const onAutoTagClick = useAutoTagTrigger( + () => runAutoTag(), + () => setDialogOpen({ autoTagAlert: true }) + ); function renderScanDialog() { if (!dialogOpen.scan) { @@ -484,8 +482,8 @@ export const LibraryTasks: React.FC = () => { /> saveInterface({ disableAutoTagWarning: v })} /> diff --git a/ui/v2.5/src/components/Shared/AutoTagConfirmDialog.tsx b/ui/v2.5/src/components/Shared/AutoTagConfirmDialog.tsx index ece07735f..c466efeed 100644 --- a/ui/v2.5/src/components/Shared/AutoTagConfirmDialog.tsx +++ b/ui/v2.5/src/components/Shared/AutoTagConfirmDialog.tsx @@ -4,6 +4,7 @@ import { FormattedMessage, useIntl } from "react-intl"; import { faExclamationTriangle } from "@fortawesome/free-solid-svg-icons"; import { useConfigureInterface } from "src/core/StashService"; import { SettingStateContext } from "src/components/Settings/context"; +import { useToast } from "src/hooks/Toast"; import { ModalComponent } from "./Modal"; import { Icon } from "./Icon"; @@ -34,30 +35,28 @@ export const AutoTagConfirmDialog: React.FC = ({ onCancel, }) => { const intl = useIntl(); + const Toast = useToast(); const [dontShowAgain, setDontShowAgain] = useState(false); const [configureInterface] = useConfigureInterface(); + // route through SettingsContext when available so the Settings panel's + // local state reflects the change without a page refresh + const settingsContext = useContext(SettingStateContext); useEffect(() => { if (show) { setDontShowAgain(false); } }, [show]); - // route through SettingsContext when available so the Settings panel's - // local state reflects the change without a page refresh - const settingsContext = useContext(SettingStateContext); - async function handleConfirm() { + function handleConfirm() { if (dontShowAgain) { - try { - if (settingsContext) { - settingsContext.saveInterface({ disableAutoTagWarning: true }); - } else { - await configureInterface({ - variables: { input: { disableAutoTagWarning: true } }, - }); - } - } catch (e) { - // preference persistence failure must not block the confirmed action + if (settingsContext) { + // context's saveInterface already surfaces errors via its own toast + settingsContext.saveInterface({ disableAutoTagWarning: true }); + } else { + configureInterface({ + variables: { input: { disableAutoTagWarning: true } }, + }).catch((e) => Toast.error(e)); } } onConfirm(); @@ -88,4 +87,4 @@ export const AutoTagConfirmDialog: React.FC = ({ /> ); -}; +}; \ No newline at end of file diff --git a/ui/v2.5/src/components/Shared/DetailsEditNavbar.tsx b/ui/v2.5/src/components/Shared/DetailsEditNavbar.tsx index e6196e4a9..d4b0c9114 100644 --- a/ui/v2.5/src/components/Shared/DetailsEditNavbar.tsx +++ b/ui/v2.5/src/components/Shared/DetailsEditNavbar.tsx @@ -1,7 +1,7 @@ import { Button, Dropdown, Modal, SplitButton } from "react-bootstrap"; import React, { useState } from "react"; import { FormattedMessage, useIntl } from "react-intl"; -import { useConfigurationContext } from "src/hooks/Config"; +import { useAutoTagTrigger } from "src/hooks/useAutoTagTrigger"; import { ImageInput } from "./ImageInput"; import { AutoTagConfirmDialog } from "./AutoTagConfirmDialog"; import cx from "classnames"; @@ -31,22 +31,13 @@ interface IProps { export const DetailsEditNavbar: React.FC = (props: IProps) => { const intl = useIntl(); - const { configuration } = useConfigurationContext(); const [isDeleteAlertOpen, setIsDeleteAlertOpen] = useState(false); const [isAutoTagAlertOpen, setIsAutoTagAlertOpen] = useState(false); - const skipAutoTagWarning = - configuration?.interface.disableAutoTagWarning ?? false; - - function onAutoTagClick() { - if (skipAutoTagWarning) { - if (props.onAutoTag) { - props.onAutoTag(); - } - return; - } - setIsAutoTagAlertOpen(true); - } + const onAutoTagClick = useAutoTagTrigger( + () => props.onAutoTag?.(), + () => setIsAutoTagAlertOpen(true) + ); function renderEditButton() { if (props.isNew) return; diff --git a/ui/v2.5/src/docs/en/Manual/AutoTagging.md b/ui/v2.5/src/docs/en/Manual/AutoTagging.md index 3b2cc6914..cc70c7b1f 100644 --- a/ui/v2.5/src/docs/en/Manual/AutoTagging.md +++ b/ui/v2.5/src/docs/en/Manual/AutoTagging.md @@ -51,4 +51,4 @@ Performers or Tags that have Ignore Auto tag flag added to them will be skipped ### Skip the confirmation warning -A confirmation warning is shown before Auto tag runs. If you use Auto tag frequently you can bypass this warning by ticking the **Don't show this warning again** checkbox on the warning dialog, or by enabling **Settings → Tasks → Auto Tag → Skip auto tag warning**. +A confirmation warning is shown before Auto tag runs. If you use Auto tag frequently you can bypass this warning by ticking the **Don't show this warning again** checkbox on the warning dialog, or by enabling **Settings → Tasks → Auto Tag → Disable auto tag warning**. diff --git a/ui/v2.5/src/hooks/useAutoTagTrigger.ts b/ui/v2.5/src/hooks/useAutoTagTrigger.ts new file mode 100644 index 000000000..fdd659b77 --- /dev/null +++ b/ui/v2.5/src/hooks/useAutoTagTrigger.ts @@ -0,0 +1,17 @@ +import { useConfigurationContext } from "./Config"; + +// Centralises the "skip warning" check so every entry point to auto tag +// consults the same interface flag. +export function useAutoTagTrigger( + onRun: () => void, + onOpenConfirm: () => void +) { + const { configuration } = useConfigurationContext(); + return () => { + if (configuration?.interface.disableAutoTagWarning) { + onRun(); + return; + } + onOpenConfirm(); + }; +} \ No newline at end of file diff --git a/ui/v2.5/src/locales/en-GB.json b/ui/v2.5/src/locales/en-GB.json index 4327df68c..9d390d993 100644 --- a/ui/v2.5/src/locales/en-GB.json +++ b/ui/v2.5/src/locales/en-GB.json @@ -510,9 +510,9 @@ "auto_tag": { "auto_tagging_all_paths": "Auto tagging all paths", "auto_tagging_paths": "Auto tagging the following paths", - "skip_warning": { + "disable_warning": { "description": "Skip the confirmation warning shown before running auto tag.", - "heading": "Skip auto tag warning" + "heading": "Disable auto tag warning" } }, "auto_tag_based_on_filenames": "Auto tag content based on file paths.",