diff --git a/biome.json b/biome.json index f019285..dbe49a2 100644 --- a/biome.json +++ b/biome.json @@ -19,7 +19,7 @@ "noExplicitAny": "off", "noImplicitAnyLet": "off", "recommended": true, - "noConsole": { "level": "error", "options": { "allow": ["error", "log"] } } + "noConsole": { "level": "error", "options": { "allow": ["error"] } } }, "correctness": { "useExhaustiveDependencies": "off", diff --git a/src/hooks/useAPI.tsx b/src/hooks/useAPI.tsx index 15ed1fd..29cbbb6 100644 --- a/src/hooks/useAPI.tsx +++ b/src/hooks/useAPI.tsx @@ -298,6 +298,8 @@ export function useFileUploadAPI() { onMutate: () => {}, onSuccess: (_variables) => { queryClient.invalidateQueries({ queryKey: ['GET', 'api/backgrounds'] }); + queryClient.invalidateQueries({ queryKey: ['GET', 'api/themes'] }); + queryClient.invalidateQueries({ queryKey: ['GET', 'api/themePlaylists'] }); }, }); } diff --git a/src/pages/settings/components/Theming/BackgroundModal.tsx b/src/pages/settings/components/Theming/BackgroundModal.tsx index d91d5dc..0de4c78 100644 --- a/src/pages/settings/components/Theming/BackgroundModal.tsx +++ b/src/pages/settings/components/Theming/BackgroundModal.tsx @@ -6,9 +6,12 @@ import { Group, Image, Modal, + Overlay, ScrollArea, SimpleGrid, + Stack, Text, + TextInput, } from '@mantine/core'; import { useCommonHooks } from 'hooks'; import { useFileUploadAPI, useMutationAPI } from 'hooks/useAPI'; @@ -20,13 +23,18 @@ function BackgroundModal({ backgroundModalOpened, handleBackgroundModalClose, backgroundList, + inUseBackgrounds, }: { backgroundModalOpened: boolean; handleBackgroundModalClose: () => void; backgroundList: string[]; + inUseBackgrounds: string[]; }) { const [background, setBackground] = useState(null); + const [fileName, setFileName] = useState(''); + const [newFileName, setNewFileName] = useState(''); const [err, setErr] = useState(false); + const [confirm, setConfirm] = useState(false); const { isMobile } = useCommonHooks(); const { mutateAsync: uploadAsync } = useFileUploadAPI(); const { mutateAsync } = useMutationAPI(); @@ -34,8 +42,8 @@ function BackgroundModal({ const handleFileUpload = (e: any) => { setErr(false); setBackground(e); + setFileName(e?.name); }; - return ( { - handleBackgroundModalClose(); setBackground(null); + setFileName(''); + setNewFileName(''); + handleBackgroundModalClose(); + setConfirm(false); }} fullScreen={isMobile} centered @@ -59,141 +70,251 @@ function BackgroundModal({ - - - - {backgroundList - .filter((background) => background !== 'None') - .map((background) => ( - - - {background} - - - { - mutateAsync({ - method: 'DELETE', - endpoint: 'api/backgrounds', - body: { background }, - }); - }} - > - - - - ))} - - - - - + + {confirm ? ( + + + Are you sure you want to delete {fileName}? + + {inUseBackgrounds.includes(fileName) && ( + + This background is currently in use! This will result in a blank + background on the theme. + + )} + + THIS ACTION CANNOT BE UNDONE!!! + + + + + + + + ) : ( + + + {backgroundList + .filter((background) => background !== 'None') + .map((background) => ( + + + {background} + + + { + setFileName(background); + setConfirm(true); + }} + > + + + + ))} + + + )} + - {background ? ( - - ) : ( - )} - - - + + + + setNewFileName(e.target.value)} + pr={'xl'} + pl={0} + styles={{ + input: { + color: 'var(--mantine-color-primary-0)', + borderColor: 'var(--mantine-color-primary-0)', + }, + }} + /> + + + {background ? ( + + ) : ( + + )} + + + + + diff --git a/src/pages/settings/components/Theming/Themes.tsx b/src/pages/settings/components/Theming/Themes.tsx index fdda20f..242275b 100644 --- a/src/pages/settings/components/Theming/Themes.tsx +++ b/src/pages/settings/components/Theming/Themes.tsx @@ -37,6 +37,7 @@ function ThemesSettings() { const [colorId, setColorId] = useState(''); const [colorValue, setColorValue] = useState('#000000'); const [backgroundList, setBackgroundList] = useState(['None']); + const [inUseBackgrounds, setInUseBackgrounds] = useState([]); const [selectedTheme, setSelectedTheme] = useState({ id: undefined, name: 'default', @@ -119,6 +120,23 @@ function ThemesSettings() { setIsLoading(false); } }, [allThemeData, isAllThemeDataFetched, debouncedSearch]); + + useEffect(() => { + if (allThemes) { + setInUseBackgrounds([ + ...new Set( + allThemes + .filter((t) => { + if (t.backgroundImage !== 'none') { + return t.backgroundImage; + } + }) + .map((t) => t.backgroundImage), + ), + ]); + } + }, [allThemes]); + return (