From fdeea2f62630f200ff2688a00378b19a717d4e4b Mon Sep 17 00:00:00 2001 From: sethburkart123 Date: Sun, 8 Sep 2024 21:51:14 +1000 Subject: [PATCH] feat(settings): add custom theme selector --- src/old-interface/components/ThemeCover.tsx | 2 +- .../components/ThemeSelector.tsx | 2 +- src/old-interface/hooks/ThemeManagment.ts | 2 +- src/seqta/ui/themes/UpdateThemePreview.ts | 2 +- src/seqta/ui/themes/applyTheme.ts | 2 +- src/seqta/ui/themes/deleteTheme.ts | 2 +- src/seqta/ui/themes/disableTheme.ts | 2 +- src/seqta/ui/themes/enableCurrent.ts | 2 +- src/seqta/ui/themes/getAvailableThemes.ts | 11 +- src/seqta/ui/themes/getTheme.ts | 22 +- src/seqta/ui/themes/removeTheme.ts | 2 +- src/seqta/ui/themes/saveTheme.ts | 2 +- src/seqta/ui/themes/setTheme.ts | 2 +- .../components/themes/ThemeSelector.svelte | 203 ++++++++++++++++++ .../pages/settings/theme.svelte | 2 + src/{old-interface => }/types/CustomThemes.ts | 4 +- 16 files changed, 224 insertions(+), 40 deletions(-) create mode 100644 src/svelte-interface/components/themes/ThemeSelector.svelte rename src/{old-interface => }/types/CustomThemes.ts (90%) diff --git a/src/old-interface/components/ThemeCover.tsx b/src/old-interface/components/ThemeCover.tsx index d6ae88ae..bc6a2c06 100644 --- a/src/old-interface/components/ThemeCover.tsx +++ b/src/old-interface/components/ThemeCover.tsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { CustomTheme, DownloadedTheme } from '../types/CustomThemes'; +import { CustomTheme, DownloadedTheme } from '../../types/CustomThemes'; import browser from 'webextension-polyfill'; import { ArrowUpOnSquareIcon, PencilIcon } from '@heroicons/react/24/outline'; import { sendThemeUpdate, setTheme } from '../hooks/ThemeManagment'; diff --git a/src/old-interface/components/ThemeSelector.tsx b/src/old-interface/components/ThemeSelector.tsx index 75328881..b56f03e7 100644 --- a/src/old-interface/components/ThemeSelector.tsx +++ b/src/old-interface/components/ThemeSelector.tsx @@ -3,7 +3,7 @@ import { deleteTheme, disableTheme, getDownloadedThemes, listThemes, sendThemeUp import { DeleteDownloadedTheme } from '../pages/Store'; import { ThemeCover } from './ThemeCover'; import browser from 'webextension-polyfill'; -import { CustomTheme, DownloadedTheme } from '../types/CustomThemes'; +import { CustomTheme, DownloadedTheme } from '../../types/CustomThemes'; import { useSettingsContext } from '../SettingsContext'; import { SettingsState } from '../types/AppProps'; import { InstallTheme } from '../../seqta/ui/themes/downloadTheme'; diff --git a/src/old-interface/hooks/ThemeManagment.ts b/src/old-interface/hooks/ThemeManagment.ts index 74d56183..f87319f9 100644 --- a/src/old-interface/hooks/ThemeManagment.ts +++ b/src/old-interface/hooks/ThemeManagment.ts @@ -1,5 +1,5 @@ import browser from 'webextension-polyfill' -import { CustomTheme, DownloadedTheme, ThemeList } from '../types/CustomThemes'; +import { CustomTheme, DownloadedTheme, ThemeList } from '../../types/CustomThemes'; import localforage from 'localforage'; export const setTheme = async (themeID: string) => { diff --git a/src/seqta/ui/themes/UpdateThemePreview.ts b/src/seqta/ui/themes/UpdateThemePreview.ts index 26002f75..08f1e23c 100644 --- a/src/seqta/ui/themes/UpdateThemePreview.ts +++ b/src/seqta/ui/themes/UpdateThemePreview.ts @@ -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'; diff --git a/src/seqta/ui/themes/applyTheme.ts b/src/seqta/ui/themes/applyTheme.ts index 9851c8fd..04f75bb1 100644 --- a/src/seqta/ui/themes/applyTheme.ts +++ b/src/seqta/ui/themes/applyTheme.ts @@ -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'; diff --git a/src/seqta/ui/themes/deleteTheme.ts b/src/seqta/ui/themes/deleteTheme.ts index 03451eaf..1ced7a77 100644 --- a/src/seqta/ui/themes/deleteTheme.ts +++ b/src/seqta/ui/themes/deleteTheme.ts @@ -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'; diff --git a/src/seqta/ui/themes/disableTheme.ts b/src/seqta/ui/themes/disableTheme.ts index f45d5fc0..4876c201 100644 --- a/src/seqta/ui/themes/disableTheme.ts +++ b/src/seqta/ui/themes/disableTheme.ts @@ -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'; diff --git a/src/seqta/ui/themes/enableCurrent.ts b/src/seqta/ui/themes/enableCurrent.ts index 94a05076..6a6a0374 100644 --- a/src/seqta/ui/themes/enableCurrent.ts +++ b/src/seqta/ui/themes/enableCurrent.ts @@ -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'; diff --git a/src/seqta/ui/themes/getAvailableThemes.ts b/src/seqta/ui/themes/getAvailableThemes.ts index 0d86f2f0..e2d1d464 100644 --- a/src/seqta/ui/themes/getAvailableThemes.ts +++ b/src/seqta/ui/themes/getAvailableThemes.ts @@ -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 => { +export const getAvailableThemes = async (): Promise => { 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; }) ); diff --git a/src/seqta/ui/themes/getTheme.ts b/src/seqta/ui/themes/getTheme.ts index 36b3cd7e..762010bd 100644 --- a/src/seqta/ui/themes/getTheme.ts +++ b/src/seqta/ui/themes/getTheme.ts @@ -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 => { +export const getTheme = async (themeId: string): Promise => { 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; diff --git a/src/seqta/ui/themes/removeTheme.ts b/src/seqta/ui/themes/removeTheme.ts index a78cebce..ef3a1e37 100644 --- a/src/seqta/ui/themes/removeTheme.ts +++ b/src/seqta/ui/themes/removeTheme.ts @@ -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) => { diff --git a/src/seqta/ui/themes/saveTheme.ts b/src/seqta/ui/themes/saveTheme.ts index 5be6bc3e..c1a272ae 100644 --- a/src/seqta/ui/themes/saveTheme.ts +++ b/src/seqta/ui/themes/saveTheme.ts @@ -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'; diff --git a/src/seqta/ui/themes/setTheme.ts b/src/seqta/ui/themes/setTheme.ts index 5e414b39..6e560cea 100644 --- a/src/seqta/ui/themes/setTheme.ts +++ b/src/seqta/ui/themes/setTheme.ts @@ -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'; diff --git a/src/svelte-interface/components/themes/ThemeSelector.svelte b/src/svelte-interface/components/themes/ThemeSelector.svelte new file mode 100644 index 00000000..c72a9f7f --- /dev/null +++ b/src/svelte-interface/components/themes/ThemeSelector.svelte @@ -0,0 +1,203 @@ + + +
+
+
+
+
+ + + + + + + Import Theme +
+
+
+
+

Themes

+
+ {#if themes} + {#each themes.themes as theme (theme.id)} + + {/each} + {/if} + + {#if tempTheme} +
+ + + + +
+ {/if} + + {#if themes && themes.themes.length > 0} +
+ {/if} + + + + Theme Store + + + +
+
\ No newline at end of file diff --git a/src/svelte-interface/pages/settings/theme.svelte b/src/svelte-interface/pages/settings/theme.svelte index 37cf35cf..93d5fcba 100644 --- a/src/svelte-interface/pages/settings/theme.svelte +++ b/src/svelte-interface/pages/settings/theme.svelte @@ -1,5 +1,6 @@