feat(settings): add custom theme selector

This commit is contained in:
sethburkart123
2024-09-08 21:51:14 +10:00
parent 272deb2b8c
commit fdeea2f626
16 changed files with 224 additions and 40 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
import type { CustomThemeBase64 } from '@/old-interface/types/CustomThemes';
import type { CustomThemeBase64 } from '@/types/CustomThemes';
import { applyCustomCSS, imageData, removeImageFromDocument, UpdateImageData } from './Themes';
import { settingsState } from '@/seqta/utils/listeners/SettingsState';
+1 -1
View File
@@ -1,4 +1,4 @@
import type { CustomImage, CustomTheme } from '@/old-interface/types/CustomThemes';
import type { CustomImage, CustomTheme } from '@/types/CustomThemes';
import { settingsState } from '@/seqta/utils/listeners/SettingsState';
import { applyCustomCSS } from './Themes';
+1 -1
View File
@@ -1,5 +1,5 @@
import localforage from 'localforage';
import type { CustomTheme } from '@/old-interface/types/CustomThemes';
import type { CustomTheme } from '@/types/CustomThemes';
import { removeTheme } from './removeTheme';
import { settingsState } from '@/seqta/utils/listeners/SettingsState';
+1 -1
View File
@@ -1,5 +1,5 @@
import localforage from 'localforage';
import type { CustomTheme } from '@/old-interface/types/CustomThemes';
import type { CustomTheme } from '@/types/CustomThemes';
import { removeTheme } from './removeTheme';
import { Mutex } from '@/seqta/utils/mutex';
import { settingsState } from '@/seqta/utils/listeners/SettingsState';
+1 -1
View File
@@ -1,5 +1,5 @@
import localforage from 'localforage';
import type { CustomTheme } from '@/old-interface/types/CustomThemes';
import type { CustomTheme } from '@/types/CustomThemes';
import { applyTheme } from './applyTheme';
import { settingsState } from '@/seqta/utils/listeners/SettingsState';
+3 -8
View File
@@ -1,20 +1,15 @@
import localforage from 'localforage';
import type { CustomTheme, ThemeList } from '@/old-interface/types/CustomThemes';
import { blobToBase64 } from '@/seqta/utils/blobToBase64';
import type { CustomTheme, ThemeList } from '@/types/CustomThemes';
import { settingsState } from '@/seqta/utils/listeners/SettingsState';
export const getAvailableThemes = async (): Promise<ThemeList | {}> => {
export const getAvailableThemes = async (): Promise<ThemeList> => {
try {
const themeIds = await localforage.getItem('customThemes') as string[] | null;
if (themeIds) {
const themes = await Promise.all(
themeIds.map(async (id) => {
const theme = await localforage.getItem(id) as CustomTheme;
const { CustomImages, ...themeWithoutImages } = theme;
return {
...themeWithoutImages,
coverImage: theme.coverImage ? await blobToBase64(theme.coverImage as Blob) : '',
};
return theme;
})
);
+3 -19
View File
@@ -1,28 +1,12 @@
import localforage from 'localforage';
import type { CustomImageBase64, CustomTheme, CustomThemeBase64 } from '@/old-interface/types/CustomThemes';
import { blobToBase64 } from '@/seqta/utils/blobToBase64';
import type { CustomTheme } from '@/types/CustomThemes';
export const getTheme = async (themeId: string): Promise<CustomThemeBase64 | null> => {
export const getTheme = async (themeId: string): Promise<CustomTheme | null> => {
try {
const theme = await localforage.getItem(themeId) as CustomTheme;
const CustomImages: CustomImageBase64[] = await Promise.all(
theme.CustomImages.map(async (image) => {
const base64 = await blobToBase64(image.blob);
return {
id: image.id,
variableName: image.variableName,
url: base64,
};
})
);
return {
...theme,
coverImage: theme.coverImage ? await blobToBase64(theme.coverImage as Blob) : null,
CustomImages,
};
return theme;
} catch (error) {
console.error('Error getting theme:', error);
return null;
+1 -1
View File
@@ -1,5 +1,5 @@
import localforage from 'localforage';
import type { CustomTheme } from '@/old-interface/types/CustomThemes';
import type { CustomTheme } from '@/types/CustomThemes';
import { settingsState } from '@/seqta/utils/listeners/SettingsState';
export const removeTheme = async (theme: CustomTheme) => {
+1 -1
View File
@@ -1,5 +1,5 @@
import localforage from 'localforage';
import type { CustomTheme, CustomThemeBase64 } from '@/old-interface/types/CustomThemes';
import type { CustomTheme, CustomThemeBase64 } from '@/types/CustomThemes';
import { disableTheme } from './disableTheme';
+1 -1
View File
@@ -1,5 +1,5 @@
import localforage from 'localforage';
import type { CustomTheme } from '@/old-interface/types/CustomThemes';
import type { CustomTheme } from '@/types/CustomThemes';
import { applyTheme } from './applyTheme';
import { removeTheme } from './removeTheme';
import { settingsState } from '@/seqta/utils/listeners/SettingsState';