separate thems into separate files

This commit is contained in:
SethBurkart123
2024-04-05 09:36:59 +11:00
parent 38c31b88e6
commit f1346ab86e
15 changed files with 340 additions and 295 deletions
+39
View File
@@ -0,0 +1,39 @@
import localforage from 'localforage';
import { CustomTheme, CustomThemeBase64 } from '../../../interface/types/CustomThemes';
import { disableTheme } from './disableTheme';
export const saveTheme = async (theme: CustomThemeBase64) => {
try {
const updatedTheme: CustomTheme = {
...theme,
CustomImages: await Promise.all(
theme.CustomImages.map(async (image) => ({
id: image.id,
blob: await fetch(image.url).then((res) => res.blob()),
variableName: image.variableName,
}))
),
};
disableTheme();
console.debug('Theme to save:', updatedTheme);
await localforage.setItem(updatedTheme.id, updatedTheme);
await localforage.getItem('customThemes').then((themes: unknown) => {
const themeList = themes as string[] | null;
if (themeList) {
if (!themeList.includes(updatedTheme.id)) {
themeList.push(updatedTheme.id);
localforage.setItem('customThemes', themeList);
}
} else {
localforage.setItem('customThemes', [updatedTheme.id]);
}
});
console.debug('Theme saved successfully!');
} catch (error) {
console.error('Error saving theme:', error);
}
};