diff --git a/src/hooks/useAPI.tsx b/src/hooks/useAPI.tsx index 29cbbb6..e7ea664 100644 --- a/src/hooks/useAPI.tsx +++ b/src/hooks/useAPI.tsx @@ -135,6 +135,8 @@ export function useMutationAPI() { queryClient.refetchQueries({ queryKey: ['GET', 'api/bookmarkCategories'] }); endpoint === 'api/applicationOrder' && queryClient.refetchQueries({ queryKey: ['GET', 'api/applicationOrder'] }); + endpoint === 'api/bookmarks' && + queryClient.refetchQueries({ queryKey: ['GET', 'api/themes'] }); }, onSuccess: (_, { endpoint }) => { queryClient.refetchQueries({ @@ -146,6 +148,8 @@ export function useMutationAPI() { queryClient.refetchQueries({ queryKey: ['GET', 'api/bookmarkCategories'] }); endpoint === 'api/applicationOrder' && queryClient.refetchQueries({ queryKey: ['GET', 'api/applicationOrder'] }); + endpoint === 'api/bookmarks' && + queryClient.refetchQueries({ queryKey: ['GET', 'api/themes'] }); }, }); } diff --git a/src/pages/settings/components/Theming/BackgroundModal.tsx b/src/pages/settings/components/Theming/BackgroundModal.tsx index 0de4c78..181af12 100644 --- a/src/pages/settings/components/Theming/BackgroundModal.tsx +++ b/src/pages/settings/components/Theming/BackgroundModal.tsx @@ -16,8 +16,8 @@ import { import { useCommonHooks } from 'hooks'; import { useFileUploadAPI, useMutationAPI } from 'hooks/useAPI'; import { useState } from 'react'; -import { FiTrash } from 'react-icons/fi'; -import { modalClasses, scrollAreaClasses } from 'styles'; +import { FiEdit, FiTrash } from 'react-icons/fi'; +import { modalClasses, scrollAreaClasses, textInputClasses } from 'styles'; function BackgroundModal({ backgroundModalOpened, @@ -33,8 +33,10 @@ function BackgroundModal({ const [background, setBackground] = useState(null); const [fileName, setFileName] = useState(''); const [newFileName, setNewFileName] = useState(''); + const [rename, setRename] = useState(''); const [err, setErr] = useState(false); const [confirm, setConfirm] = useState(false); + const [editing, setEditing] = useState(false); const { isMobile } = useCommonHooks(); const { mutateAsync: uploadAsync } = useFileUploadAPI(); const { mutateAsync } = useMutationAPI(); @@ -56,6 +58,7 @@ function BackgroundModal({ setNewFileName(''); handleBackgroundModalClose(); setConfirm(false); + setEditing(false); }} fullScreen={isMobile} centered @@ -72,7 +75,7 @@ function BackgroundModal({ - {confirm ? ( + {confirm && ( - ) : ( + )} + {editing && ( + + + Editing {fileName} + + {inUseBackgrounds.includes(fileName) && ( + + Updating the name will update the associated themes. + + )} + + setRename(e.target.value)} + /> + + + + + + + + )} + {!editing && !confirm && ( + { + setFileName(background); + setEditing(true); + }} + > + + - {confirm && ( - - )} + {confirm || + (editing && ( + + ))} { const newThemeList = themeList; return ( - { - const newSelectedPlaylist = { ...selectedPlaylist }; - if (themeList?.includes(miniTheme.id)) { - newThemeList.splice(themeList.indexOf(miniTheme.id), 1); - } else { - newThemeList.push(miniTheme.id); - } - newSelectedPlaylist.themeList = JSON.stringify(newThemeList); - setSelectedPlaylist(newSelectedPlaylist); - }} - > - - + newThemeList={newThemeList} + miniTheme={miniTheme} + themeList={themeList} + allThemes={allThemes} + selectedPlaylist={selectedPlaylist} + setSelectedPlaylist={setSelectedPlaylist} + /> ); })} diff --git a/src/pages/settings/components/Theming/ThemePlaylists.tsx b/src/pages/settings/components/Theming/ThemePlaylists.tsx index b96a03c..a030762 100644 --- a/src/pages/settings/components/Theming/ThemePlaylists.tsx +++ b/src/pages/settings/components/Theming/ThemePlaylists.tsx @@ -68,6 +68,7 @@ function ThemePlaylists() { setIsLoading(false); } }, [themePlaylistData, isThemePlaylistDataFetched, debouncedSearch]); + return ( a.name === 'Time of Day', + )[0]?.id ?? undefined, name: 'Time of Day', default: 1, themeList: diff --git a/src/pages/settings/components/Theming/ThemePreivewMiddleware.tsx b/src/pages/settings/components/Theming/ThemePreivewMiddleware.tsx new file mode 100644 index 0000000..adfafff --- /dev/null +++ b/src/pages/settings/components/Theming/ThemePreivewMiddleware.tsx @@ -0,0 +1,85 @@ +import { Group, Overlay, Popover } from '@mantine/core'; +import { useLongPress } from '@mantine/hooks'; +import { useState } from 'react'; +import ThemeMiniCard from './ThemeMiniCard'; +import ThemeModalContent from './ThemeModalContent'; + +function ThemePreviewMiddleware({ + newThemeList, + miniTheme, + themeList, + allThemes, + selectedPlaylist, + setSelectedPlaylist, +}: { + newThemeList: number[]; + miniTheme: any; + themeList: number[]; + allThemes: any; + selectedPlaylist: any; + setSelectedPlaylist: (selectedPlaylist: any) => void; +}) { + const [pressed, setPressed] = useState(false); + const handlers = useLongPress(() => { + setPressed(true); + }); + return ( + + + { + if (!pressed) { + const newSelectedPlaylist = { ...selectedPlaylist }; + if (themeList?.includes(miniTheme.id)) { + newThemeList.splice(themeList.indexOf(miniTheme.id), 1); + } else { + newThemeList.push(miniTheme.id); + } + newSelectedPlaylist.themeList = JSON.stringify(newThemeList); + setSelectedPlaylist(newSelectedPlaylist); + } else { + setPressed(false); + } + }} + > + + + + + + + + + ); +} + +export default ThemePreviewMiddleware; diff --git a/src/pages/settings/components/Theming/ThemeSelect.tsx b/src/pages/settings/components/Theming/ThemeSelect.tsx index c900232..fece27c 100644 --- a/src/pages/settings/components/Theming/ThemeSelect.tsx +++ b/src/pages/settings/components/Theming/ThemeSelect.tsx @@ -59,9 +59,17 @@ function ThemeSelect({ textAlign: 'center', height: '60px', color: theme?.primaryColor, - background: `linear-gradient(${theme?.backgroundColor}33, ${theme?.backgroundColor}33), no-repeat center url(../../api/backgroundImages/${theme?.backgroundImage})`, - backgroundSize: 'cover', - backgroundColor: theme?.backgroundColor, + backgroundImage: + theme?.backgroundImage.toLocaleLowerCase() !== 'none' + ? `linear-gradient(${theme?.backgroundColor}33, ${theme?.backgroundColor}33), url(../../api/backgroundImages/${theme?.backgroundImage})` + : undefined, + backgroundSize: + theme?.backgroundImage.toLocaleLowerCase() !== 'none' ? 'cover' : undefined, + backgroundColor: + theme?.backgroundImage.toLocaleLowerCase() === 'none' + ? theme?.backgroundColor + : undefined, + backgroundPosition: 'center', border: `solid ${theme?.borderColor}`, borderRadius: '8px', }, @@ -78,9 +86,19 @@ function ThemeSelect({ w={'100%'} h={'60px'} style={{ - background: `linear-gradient(${theme?.backgroundColor}33, ${theme?.backgroundColor}33), no-repeat center url(../../api/backgroundImages/${theme?.backgroundImage})`, - backgroundSize: 'cover', - backgroundColor: theme?.backgroundColor, + backgroundImage: + theme?.backgroundImage.toLocaleLowerCase() !== 'none' + ? `linear-gradient(${theme?.backgroundColor}33, ${theme?.backgroundColor}33), url(../../api/backgroundImages/${theme?.backgroundImage})` + : undefined, + backgroundSize: + theme?.backgroundImage.toLocaleLowerCase() !== 'none' + ? 'cover' + : undefined, + backgroundColor: + theme?.backgroundImage.toLocaleLowerCase() === 'none' + ? theme?.backgroundColor + : undefined, + backgroundPosition: 'center', border: `solid ${theme?.borderColor}`, borderRadius: '8px', }}