mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-06 03:34:40 +00:00
separate thems into separate files
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user