diff --git a/interface/src/components/BackgroundSelector.tsx b/interface/src/components/BackgroundSelector.tsx index ccc11fd9..b4c925b6 100644 --- a/interface/src/components/BackgroundSelector.tsx +++ b/interface/src/components/BackgroundSelector.tsx @@ -15,12 +15,16 @@ export interface Background { isDownloaded?: boolean; } -export default function BackgroundSelector() { +interface BackgroundSelectorProps { + selectedType: "background" | "theme"; + isEditMode: boolean; +} + +export default function BackgroundSelector({ selectedType, isEditMode }: BackgroundSelectorProps) { const [backgrounds, setBackgrounds] = useState([]); const [selectedBackground, setSelectedBackground] = useState(localStorage.getItem('selectedBackground')); const [downloadedPresetIds, setDownloadedPresetIds] = useState([]); const [downloadProgress, setDownloadProgress] = useState>({}); - const [isEditMode, setIsEditMode] = useState(false); const handleFileChange = async (e: ChangeEvent): Promise => { const file = e.target.files?.[0]; @@ -89,6 +93,7 @@ export default function BackgroundSelector() { }; const selectNoBackground = (): void => { + disableTheme(); setSelectedBackground(null); localStorage.removeItem('selectedBackground'); }; @@ -105,9 +110,6 @@ export default function BackgroundSelector() { {selectedBackground == null ? 'No Background' : 'Remove Background'}
-

Images

{/* Image uploader swatch */} @@ -121,7 +123,7 @@ export default function BackgroundSelector() { {backgrounds.filter(bg => bg.type === 'image').map(bg => (
selectBackground(bg.id)} - className={`relative w-16 h-16 cursor-pointer rounded-xl transition ring dark:ring-white ring-zinc-300 ${isEditMode ? 'animate-shake' : ''} ${selectedBackground === bg.id ? 'dark:ring-2 ring-4' : 'ring-0'}`}> + className={`relative w-16 h-16 cursor-pointer rounded-xl transition ring dark:ring-white ring-zinc-300 ${isEditMode ? 'animate-shake' : ''} ${selectedBackground === bg.id && selectedType === "background" ? 'dark:ring-2 ring-4' : 'ring-0'}`}> {isEditMode && (
deleteBackground(bg.id)}> @@ -167,7 +169,7 @@ export default function BackgroundSelector() {
{backgrounds.filter(bg => bg.type === 'video').map(bg => ( -
selectBackground(bg.id)} className={`relative w-16 h-16 cursor-pointer rounded-xl transition ring dark:ring-white ring-zinc-300 ${isEditMode ? 'animate-shake' : ''} ${selectedBackground === bg.id ? 'dark:ring-2 ring-4' : 'ring-0'}`}> +
selectBackground(bg.id)} className={`relative w-16 h-16 cursor-pointer rounded-xl transition ring dark:ring-white ring-zinc-300 ${isEditMode ? 'animate-shake' : ''} ${selectedBackground === bg.id && selectedType === "background" ? 'dark:ring-2 ring-4' : 'ring-0'}`}> {isEditMode && (
deleteBackground(bg.id)}> diff --git a/interface/src/pages/Themes.tsx b/interface/src/pages/Themes.tsx index a43fd084..9dc42583 100644 --- a/interface/src/pages/Themes.tsx +++ b/interface/src/pages/Themes.tsx @@ -1,13 +1,22 @@ -import { FC } from 'react'; +import { FC, useEffect, useState } from 'react'; import BackgroundSelector from '../components/BackgroundSelector'; import ThemeSelector from '../components/ThemeSelector'; const Themes: FC = () => { + const [isEditMode, setIsEditMode] = useState(false); + const [selectedType, setSelectedType] = useState<'background' | 'theme'>('background'); + + useEffect(() => { + setSelectedType('background'); + }, []) return (
- - + + +
); }; diff --git a/src/seqta/ui/Themes.js b/src/seqta/ui/Themes.js index 188f4dad..5853237b 100644 --- a/src/seqta/ui/Themes.js +++ b/src/seqta/ui/Themes.js @@ -101,14 +101,14 @@ export const setTheme = async (themeName, themeUrl) => { await downloadTheme(themeName, themeUrl); } - localStorage.setItem("selectedTheme", themeName); + localforage.setItem("selectedTheme", themeName); await applyTheme(themeName).catch((error) => { console.error(`Failed to apply theme: ${error}`); }); }; export const enableCurrentTheme = async () => { - const currentTheme = localStorage.getItem("selectedTheme"); + const currentTheme = localforage.getItem("selectedTheme"); if (currentTheme) { console.log(`Enabling current theme: ${currentTheme}`); @@ -116,7 +116,7 @@ export const enableCurrentTheme = async () => { console.error(`Failed to apply current theme: ${error}`); }); } else { - console.log("No current theme set in localStorage."); + console.log("No current theme set in localforage."); } }; @@ -136,7 +136,7 @@ export const disableTheme = async () => { } // Remove any applied image URLs from the root element - const currentTheme = localStorage.getItem("selectedTheme"); + const currentTheme = localforage.getItem("selectedTheme"); if (currentTheme) { const themeData = await localforage.getItem(`css_${currentTheme}`); if (themeData && themeData.images) { @@ -147,7 +147,7 @@ export const disableTheme = async () => { console.log("Current theme's images removed."); } - // Clear the selected theme from localStorage - localStorage.removeItem("selectedTheme"); + // Clear the selected theme from localforage + localforage.removeItem("selectedTheme"); console.log("Current theme disabled."); }; \ No newline at end of file diff --git a/src/seqta/utils/StorageListener.js b/src/seqta/utils/StorageListener.js index 09d83ee2..bcbe30e8 100644 --- a/src/seqta/utils/StorageListener.js +++ b/src/seqta/utils/StorageListener.js @@ -19,46 +19,58 @@ export default class StorageListener { } handleStorageChanges(changes) { - if (changes.selectedColor) { - this.handleSelectedColorChange(changes.selectedColor.newValue); - } + Object.keys(changes).forEach((changeKey) => { + switch (changeKey) { - if (changes.shortcuts) { - this.handleShortcutsChange( - changes.shortcuts.oldValue, - changes.shortcuts.newValue - ); - } + case "selectedColor": + this.handleSelectedColorChange(changes.selectedColor.newValue); + break; - if (changes.DarkMode) { - this.darkMode = changes.DarkMode.newValue; - console.log(this.darkMode); - } + case "shortcuts": + this.handleShortcutsChange( + changes.shortcuts.oldValue, + changes.shortcuts.newValue + ); + break; - if (changes?.customshortcuts?.newValue) { - this.handleCustomShortcutsChange( - changes.customshortcuts.oldValue, - changes.customshortcuts.newValue - ); - } + case "DarkMode": + this.darkMode = changes.DarkMode.newValue; + console.log(this.darkMode); + break; - if (changes.notificationcollector) { - this.handleNotificationCollectorChange(changes.notificationcollector); - } + case "customshortcuts": + if (changes.customshortcuts.newValue) { + this.handleCustomShortcutsChange( + changes.customshortcuts.oldValue, + changes.customshortcuts.newValue + ); + } + break; - if (changes.bksliderinput) { - updateBgDurations(changes.bksliderinput.newValue); - } + case "notificationcollector": + this.handleNotificationCollectorChange(changes.notificationcollector); + break; - if (changes.animatedbk !== undefined) { - if (changes.animatedbk.newValue) { - CreateBackground(); - } else { - RemoveBackground(); - document.getElementById("container").style.background = "var(--background-secondary)"; + case "bksliderinput": + updateBgDurations(changes.bksliderinput.newValue); + break; + + case "animatedbk": + if (changes.animatedbk.newValue) { + CreateBackground(); + } else { + RemoveBackground(); + document.getElementById("container").style.background = "var(--background-secondary)"; + } + break; + + // Add default case if you need to handle a case where changeKey does not match any case + default: + // Handle unknown changeKey if necessary + break; } - } - } + }); + } handleSelectedColorChange(newColor) { try {