From 9c9e5dff7681bec772ca890132cd84f0de8a54d1 Mon Sep 17 00:00:00 2001 From: Xylight Date: Thu, 25 Jul 2024 11:49:54 -0700 Subject: [PATCH] feat: add name editing --- src/lib/i18n/en.json | 6 +++++- src/lib/ui/colors.ts | 20 ++++++++++++++++++++ src/routes/theme/+page.svelte | 4 ++-- src/routes/theme/ThemePreset.svelte | 20 +++++++++++++++++--- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/lib/i18n/en.json b/src/lib/i18n/en.json index 4e4a0e3f..be77a8a5 100644 --- a/src/lib/i18n/en.json +++ b/src/lib/i18n/en.json @@ -366,7 +366,11 @@ "delete": { "title": "Delete Theme", "confirm": "Confirm" - } + }, + "default": "Default", + "classic": "Classic", + "imported": "Your Theme", + "new": "New Theme" } }, "community": { diff --git a/src/lib/ui/colors.ts b/src/lib/ui/colors.ts index a035f4a3..87630457 100644 --- a/src/lib/ui/colors.ts +++ b/src/lib/ui/colors.ts @@ -11,6 +11,7 @@ import { import { env } from '$env/dynamic/public' import { getDefaultTheme, presets } from './presets' import { browser } from '$app/environment' +import { t } from '$lib/translations' type ColorScheme = 'system' | 'light' | 'dark' @@ -164,9 +165,11 @@ function loadColorScheme() { function loadTheme() { if (!browser) return const localTheme = localStorage.getItem('themeData') + if (localTheme) { return JSON.parse(localTheme) } + return } @@ -174,4 +177,21 @@ if (browser) { try { loadColorScheme() } catch (e) {} + try { + const oldColors = localStorage.getItem('colors') + if (oldColors) { + themeData.update((td) => ({ + ...td, + themes: [ + ...td.themes, + { + id: Math.max(...td.themes.map((t) => t.id)) + 1, + colors: JSON.parse(oldColors), + name: t.get('routes.theme.preset.imported') ?? 'Your Theme', + }, + ], + })) + localStorage.removeItem('colors') + } + } catch (e) {} } diff --git a/src/routes/theme/+page.svelte b/src/routes/theme/+page.svelte index 5c3f7752..fcbf87dc 100644 --- a/src/routes/theme/+page.svelte +++ b/src/routes/theme/+page.svelte @@ -61,14 +61,14 @@ gap-4 overflow-auto max-h-72" > {#each $themeData.themes as theme} - + {/each} + {/if} {#if theme.id > 0}