From 310ff7a28145dbfa46d8506ba16e7cea4ace2f0d Mon Sep 17 00:00:00 2001 From: SethBurkart123 Date: Fri, 20 Oct 2023 07:09:38 +1100 Subject: [PATCH] added background removal --- interface/src/pages/Themes.tsx | 112 +++++++++++++++++-------------- public/backgrounds/background.js | 6 ++ 2 files changed, 67 insertions(+), 51 deletions(-) diff --git a/interface/src/pages/Themes.tsx b/interface/src/pages/Themes.tsx index f894a1c5..307bfcc2 100644 --- a/interface/src/pages/Themes.tsx +++ b/interface/src/pages/Themes.tsx @@ -88,70 +88,80 @@ const Themes: FC = () => { setBackgrounds(prev => prev.filter(bg => bg.id !== fileId)); }; + const selectNoBackground = (): void => { + setSelectedBackground(null); + localStorage.removeItem('selectedBackground'); + }; + useEffect(() => { loadBackgrounds(); }, []); return (
- +
+ -

Images

-
- {/* Image uploader swatch */} -
-
- {/* Plus icon */} -  +

Images

+
+ {/* Image uploader swatch */} +
+
+ {/* Plus icon */} +  +
+
- + {backgrounds.filter(bg => bg.type === 'image').map(bg => ( +
selectBackground(bg.id)} + className={`relative w-16 h-16 cursor-pointer rounded-xl transition ring ring-white ${isEditMode ? 'animate-shake' : ''} ${selectedBackground === bg.id ? 'ring-2' : 'ring-0'}`}> + {isEditMode && ( +
deleteBackground(bg.id)}> +
+
+ )} + swatch +
+ ))}
- {backgrounds.filter(bg => bg.type === 'image').map(bg => ( -
selectBackground(bg.id)} - className={`relative w-16 h-16 cursor-pointer rounded-xl transition ring ring-white ${isEditMode ? 'animate-shake' : ''} ${selectedBackground === bg.id ? 'ring-2' : 'ring-0'}`}> - {isEditMode && ( -
deleteBackground(bg.id)}> -
-
- )} - swatch -
- ))} -
-

Videos

-
- {/* Video uploader swatch */} -
-
- {/* Plus icon */} -  +

Videos

+
+ {/* Video uploader swatch */} +
+
+ {/* Plus icon */} +  +
+
- + {backgrounds.filter(bg => bg.type === 'video').map(bg => ( +
selectBackground(bg.id)} className={`relative w-16 h-16 cursor-pointer rounded-xl transition ring ring-white ${isEditMode ? 'animate-shake' : ''} ${selectedBackground === bg.id ? 'ring-2' : 'ring-0'}`}> + {isEditMode && ( +
deleteBackground(bg.id)}> +
+
+ )} +
+ ))} +
+ + { /* Preview section */ } +
+ {backgrounds.filter(bg => bg.id === selectedBackground).map(bg => ( + bg.type === 'image' ? + Selected Background : +
- {backgrounds.filter(bg => bg.type === 'video').map(bg => ( -
selectBackground(bg.id)} className={`relative w-16 h-16 cursor-pointer rounded-xl transition ring ring-white ${isEditMode ? 'animate-shake' : ''} ${selectedBackground === bg.id ? 'ring-2' : 'ring-0'}`}> - {isEditMode && ( -
deleteBackground(bg.id)}> -
-
- )} -
- ))} -
- - { /* Preview section */ } -
- {backgrounds.filter(bg => bg.id === selectedBackground).map(bg => ( - bg.type === 'image' ? - Selected Background : -
); diff --git a/public/backgrounds/background.js b/public/backgrounds/background.js index 5aabbdfd..5c3ea234 100644 --- a/public/backgrounds/background.js +++ b/public/backgrounds/background.js @@ -37,6 +37,12 @@ const updateBackground = async () => { const data = await readData(); if (!data) { console.log("No data found in IndexedDB."); + + const container = document.getElementById("media-container"); + const currentMedia = container.querySelector(".current-media"); + if (currentMedia) { + currentMedia.remove(); + } return; }