diff --git a/src/pageEditor/hooks/useDeactivateMod.tsx b/src/pageEditor/hooks/useDeactivateMod.tsx index 22f88ae1e3..62bd2c6efe 100644 --- a/src/pageEditor/hooks/useDeactivateMod.tsx +++ b/src/pageEditor/hooks/useDeactivateMod.tsx @@ -19,6 +19,7 @@ import { useCallback } from "react"; import { type RegistryId } from "@/types/registryTypes"; import { DEACTIVATE_MOD_MODAL_PROPS, + DELETE_UNSAVED_MOD_MODAL_PROPS, useRemoveModComponentFromStorage, } from "@/pageEditor/hooks/useRemoveModComponentFromStorage"; import { useDispatch, useSelector } from "react-redux"; @@ -29,6 +30,7 @@ import { useModals } from "@/components/ConfirmationModal"; import { actions } from "@/pageEditor/store/editor/editorSlice"; import { getModComponentId } from "@/pageEditor/utils"; import { clearLog } from "@/background/messenger/api"; +import { isInnerDefinitionRegistryId } from "@/types/helpers"; type Config = { modId: RegistryId; @@ -36,7 +38,8 @@ type Config = { }; /** - * This hook provides a callback function to deactivate a mod and remove it from the Page Editor + * This hook provides a callback function to deactivate a mod and remove it from the Page Editor. Note that in the case + * of unsaved mods, the mod will be deleted instead of deactivated. */ function useDeactivateMod(): (useDeactivateConfig: Config) => Promise { const dispatch = useDispatch(); @@ -48,7 +51,12 @@ function useDeactivateMod(): (useDeactivateConfig: Config) => Promise { return useCallback( async ({ modId, shouldShowConfirmation = true }) => { if (shouldShowConfirmation) { - const confirmed = await showConfirmation(DEACTIVATE_MOD_MODAL_PROPS); + const isUnsavedMod = isInnerDefinitionRegistryId(modId); + const confirmed = await showConfirmation( + isUnsavedMod + ? DELETE_UNSAVED_MOD_MODAL_PROPS + : DEACTIVATE_MOD_MODAL_PROPS, + ); if (!confirmed) { return; diff --git a/src/pageEditor/hooks/useRemoveModComponentFromStorage.tsx b/src/pageEditor/hooks/useRemoveModComponentFromStorage.tsx index 27f4dd2a53..b1470c0a52 100644 --- a/src/pageEditor/hooks/useRemoveModComponentFromStorage.tsx +++ b/src/pageEditor/hooks/useRemoveModComponentFromStorage.tsx @@ -59,6 +59,17 @@ export const DEACTIVATE_MOD_MODAL_PROPS: ConfirmationModalProps = { submitCaption: "Deactivate", }; +export const DELETE_UNSAVED_MOD_MODAL_PROPS: ConfirmationModalProps = { + title: "Delete Mod?", + message: ( + <> + This action cannot be undone. If you'd like to deactivate this mod + instead, save the mod first. + + ), + submitCaption: "Delete", +}; + /** * Returns a callback that removes a mod component from the Page Editor and Mod Component Storage. * diff --git a/src/pageEditor/modListingPanel/ModActionMenu.tsx b/src/pageEditor/modListingPanel/ModActionMenu.tsx index 775ab7a351..63870f8592 100644 --- a/src/pageEditor/modListingPanel/ModActionMenu.tsx +++ b/src/pageEditor/modListingPanel/ModActionMenu.tsx @@ -22,6 +22,7 @@ import { faHistory, faPlus, faTimes, + faTrash, } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import styles from "./ActionMenu.module.scss"; @@ -91,8 +92,10 @@ const ModActionMenu: React.FC<{ }, }, { - title: "Deactivate", - icon: , + title: isUnsavedMod ? "Delete" : "Deactivate", + icon: ( + + ), async action() { await deactivateMod({ modId }); },