Background modal updates

This commit is contained in:
Sean Edmunds
2025-06-20 13:56:00 -05:00
parent 34c6b272c8
commit b122b1af18
4 changed files with 277 additions and 135 deletions

View File

@@ -19,7 +19,7 @@
"noExplicitAny": "off", "noExplicitAny": "off",
"noImplicitAnyLet": "off", "noImplicitAnyLet": "off",
"recommended": true, "recommended": true,
"noConsole": { "level": "error", "options": { "allow": ["error", "log"] } } "noConsole": { "level": "error", "options": { "allow": ["error"] } }
}, },
"correctness": { "correctness": {
"useExhaustiveDependencies": "off", "useExhaustiveDependencies": "off",

View File

@@ -298,6 +298,8 @@ export function useFileUploadAPI() {
onMutate: () => {}, onMutate: () => {},
onSuccess: (_variables) => { onSuccess: (_variables) => {
queryClient.invalidateQueries({ queryKey: ['GET', 'api/backgrounds'] }); queryClient.invalidateQueries({ queryKey: ['GET', 'api/backgrounds'] });
queryClient.invalidateQueries({ queryKey: ['GET', 'api/themes'] });
queryClient.invalidateQueries({ queryKey: ['GET', 'api/themePlaylists'] });
}, },
}); });
} }

View File

@@ -6,9 +6,12 @@ import {
Group, Group,
Image, Image,
Modal, Modal,
Overlay,
ScrollArea, ScrollArea,
SimpleGrid, SimpleGrid,
Stack,
Text, Text,
TextInput,
} from '@mantine/core'; } from '@mantine/core';
import { useCommonHooks } from 'hooks'; import { useCommonHooks } from 'hooks';
import { useFileUploadAPI, useMutationAPI } from 'hooks/useAPI'; import { useFileUploadAPI, useMutationAPI } from 'hooks/useAPI';
@@ -20,13 +23,18 @@ function BackgroundModal({
backgroundModalOpened, backgroundModalOpened,
handleBackgroundModalClose, handleBackgroundModalClose,
backgroundList, backgroundList,
inUseBackgrounds,
}: { }: {
backgroundModalOpened: boolean; backgroundModalOpened: boolean;
handleBackgroundModalClose: () => void; handleBackgroundModalClose: () => void;
backgroundList: string[]; backgroundList: string[];
inUseBackgrounds: string[];
}) { }) {
const [background, setBackground] = useState<File | null>(null); const [background, setBackground] = useState<File | null>(null);
const [fileName, setFileName] = useState<string>('');
const [newFileName, setNewFileName] = useState<string>('');
const [err, setErr] = useState<boolean>(false); const [err, setErr] = useState<boolean>(false);
const [confirm, setConfirm] = useState<boolean>(false);
const { isMobile } = useCommonHooks(); const { isMobile } = useCommonHooks();
const { mutateAsync: uploadAsync } = useFileUploadAPI(); const { mutateAsync: uploadAsync } = useFileUploadAPI();
const { mutateAsync } = useMutationAPI(); const { mutateAsync } = useMutationAPI();
@@ -34,8 +42,8 @@ function BackgroundModal({
const handleFileUpload = (e: any) => { const handleFileUpload = (e: any) => {
setErr(false); setErr(false);
setBackground(e); setBackground(e);
setFileName(e?.name);
}; };
return ( return (
<Modal.Root <Modal.Root
size={'75%'} size={'75%'}
@@ -43,8 +51,11 @@ function BackgroundModal({
classNames={modalClasses} classNames={modalClasses}
opened={backgroundModalOpened} opened={backgroundModalOpened}
onClose={() => { onClose={() => {
handleBackgroundModalClose();
setBackground(null); setBackground(null);
setFileName('');
setNewFileName('');
handleBackgroundModalClose();
setConfirm(false);
}} }}
fullScreen={isMobile} fullScreen={isMobile}
centered centered
@@ -59,7 +70,81 @@ function BackgroundModal({
</Group> </Group>
<Modal.CloseButton /> <Modal.CloseButton />
</Modal.Header> </Modal.Header>
<Modal.Body p={'2rem'}> <Modal.Body p={'1rem'}>
<Stack align='center' w={'100%'}>
{confirm ? (
<Stack
justify='center'
align='center'
style={{
width: '100%',
height: '30rem',
backgroundColor: 'var(--mantine-color-search-0)',
padding: '1rem',
borderRadius: '.5rem',
backgroundFilter: 'blur(5px)',
}}
>
<Text fw={600} fz={'2rem'}>
Are you sure you want to delete {fileName}?
</Text>
{inUseBackgrounds.includes(fileName) && (
<Text fw={600} fz={'1.5rem'}>
This background is currently in use! This will result in a blank
background on the theme.
</Text>
)}
<Text fw={600} fz={'3rem'}>
THIS ACTION CANNOT BE UNDONE!!!
</Text>
<Card
style={{
aspectRatio: '16/9',
height: '100%',
backgroundImage: `url(../../api/backgroundImages/${fileName})`,
backgroundSize: 'cover',
backgroundPosition: 'center',
backgroundRepeat: 'no-repeat',
padding: '2rem',
margin: '1rem',
}}
/>
<Group>
<Button
mt={'auto'}
w={'min-content'}
color='red'
onClick={() => {
setBackground(null);
setFileName('');
setNewFileName('');
setConfirm(false);
setFileName('');
mutateAsync({
method: 'DELETE',
endpoint: 'api/backgrounds',
body: { fileName },
});
}}
>
DELETE
</Button>
<Button
mt={'auto'}
w={'min-content'}
onClick={() => {
setBackground(null);
setFileName('');
setNewFileName('');
setConfirm(false);
setFileName('');
}}
>
Cancel
</Button>
</Group>
</Stack>
) : (
<ScrollArea <ScrollArea
className={scrollAreaClasses.default} className={scrollAreaClasses.default}
classNames={scrollAreaClasses} classNames={scrollAreaClasses}
@@ -113,11 +198,8 @@ function BackgroundModal({
zIndex: 3, zIndex: 3,
}} }}
onClick={() => { onClick={() => {
mutateAsync({ setFileName(background);
method: 'DELETE', setConfirm(true);
endpoint: 'api/backgrounds',
body: { background },
});
}} }}
> >
<FiTrash /> <FiTrash />
@@ -126,7 +208,24 @@ function BackgroundModal({
))} ))}
</SimpleGrid> </SimpleGrid>
</ScrollArea> </ScrollArea>
<Group gap={0} w={'100%'} align={'center'} justify='space-between'> )}
<Stack
display={'flex'}
pos={'relative'}
w={'100%'}
align={'center'}
justify='space-between'
p={16}
>
{confirm && (
<Overlay
opacity={1}
color='var(--mantine-color-search-0)'
style={{ borderRadius: '.5rem', backdropFilter: 'blur(5px)' }}
/>
)}
<Group gap={0}>
<Stack gap={0} w={'60%'}>
<FileInput <FileInput
clearable clearable
accept='image/png,image/jpeg' accept='image/png,image/jpeg'
@@ -134,13 +233,12 @@ function BackgroundModal({
onChange={handleFileUpload} onChange={handleFileUpload}
label={'Upload Background'} label={'Upload Background'}
placeholder={'Select...'} placeholder={'Select...'}
error={err && 'Please upload a background'}
description={ description={
'Max size: 50MB for upload. Images are resized to 300kb after upload.' 'Max size: 50MB for upload. Images are resized to 300kb after upload.'
} }
p={'xl'} pr={'xl'}
w={'60%'}
pl={0} pl={0}
error={err && 'Please upload a background'}
styles={{ styles={{
input: { input: {
color: 'var(--mantine-color-primary-0)', color: 'var(--mantine-color-primary-0)',
@@ -151,6 +249,21 @@ function BackgroundModal({
}, },
}} }}
/> />
<TextInput
label={'File Name'}
placeholder={fileName}
value={newFileName}
onChange={(e) => setNewFileName(e.target.value)}
pr={'xl'}
pl={0}
styles={{
input: {
color: 'var(--mantine-color-primary-0)',
borderColor: 'var(--mantine-color-primary-0)',
},
}}
/>
</Stack>
<Card <Card
style={{ style={{
aspectRatio: '16/9', aspectRatio: '16/9',
@@ -168,7 +281,7 @@ function BackgroundModal({
<Image src={URL.createObjectURL(background)} w={'100%'} h={'100%'} /> <Image src={URL.createObjectURL(background)} w={'100%'} h={'100%'} />
) : ( ) : (
<Image <Image
src={'https://placehold.co/800x450?text=Select%20an%20Image'} src={'https://placehold.co/800x450?text=Upload%20an%20Image'}
w={'100%'} w={'100%'}
h={'100%'} h={'100%'}
/> />
@@ -176,16 +289,22 @@ function BackgroundModal({
</Card> </Card>
</Group> </Group>
<Button <Button
w={'min-content'}
onClick={() => { onClick={() => {
if (background) { if (background) {
fd.append('background', background || ''); const newBackground = new File(
[background],
newFileName || background.name,
{ type: background.type },
);
fd.append('background', newBackground || '');
uploadAsync({ uploadAsync({
method: 'POST', method: 'POST',
endpoint: 'api/backgrounds', endpoint: 'api/backgrounds',
body: fd, body: fd,
}); });
handleBackgroundModalClose();
setBackground(null); setBackground(null);
setNewFileName('');
setErr(false); setErr(false);
} else { } else {
setErr(true); setErr(true);
@@ -194,6 +313,8 @@ function BackgroundModal({
> >
Upload Upload
</Button> </Button>
</Stack>
</Stack>
</Modal.Body> </Modal.Body>
</Modal.Content> </Modal.Content>
</Modal.Root> </Modal.Root>

View File

@@ -37,6 +37,7 @@ function ThemesSettings() {
const [colorId, setColorId] = useState<string>(''); const [colorId, setColorId] = useState<string>('');
const [colorValue, setColorValue] = useState('#000000'); const [colorValue, setColorValue] = useState('#000000');
const [backgroundList, setBackgroundList] = useState<string[]>(['None']); const [backgroundList, setBackgroundList] = useState<string[]>(['None']);
const [inUseBackgrounds, setInUseBackgrounds] = useState<string[]>([]);
const [selectedTheme, setSelectedTheme] = useState<Theme>({ const [selectedTheme, setSelectedTheme] = useState<Theme>({
id: undefined, id: undefined,
name: 'default', name: 'default',
@@ -119,6 +120,23 @@ function ThemesSettings() {
setIsLoading(false); setIsLoading(false);
} }
}, [allThemeData, isAllThemeDataFetched, debouncedSearch]); }, [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 ( return (
<Stack w={'100%'} align='center'> <Stack w={'100%'} align='center'>
<ThemeModal <ThemeModal
@@ -140,6 +158,7 @@ function ThemesSettings() {
backgroundModalOpened={backgroundModalOpened} backgroundModalOpened={backgroundModalOpened}
handleBackgroundModalClose={handleBackgroundModalClose} handleBackgroundModalClose={handleBackgroundModalClose}
backgroundList={backgroundList} backgroundList={backgroundList}
inUseBackgrounds={inUseBackgrounds}
/> />
<SettingsHeader <SettingsHeader
setDragging={undefined} setDragging={undefined}