mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-06-05 19:24:39 +00:00
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import localforage from 'localforage';
|
|
import type { LoadedCustomTheme } from '@/types/CustomThemes';
|
|
import { disableTheme } from './disableTheme';
|
|
|
|
|
|
export const saveTheme = async (theme: LoadedCustomTheme) => {
|
|
try {
|
|
disableTheme();
|
|
|
|
console.debug('Theme to save:', theme);
|
|
|
|
/* remove blob urls from theme */
|
|
const updatedTheme = { ...theme, CustomImages: theme.CustomImages.map((image) => ({ ...image, blob: null })) }
|
|
|
|
await localforage.setItem(theme.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);
|
|
}
|
|
};
|