storage listener uses switch

This commit is contained in:
SethBurkart123
2023-11-02 18:38:02 +11:00
parent 1c86fd3f9b
commit 7b0fc29461
4 changed files with 72 additions and 49 deletions
+6 -6
View File
@@ -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.");
};