Skip to content

Commit 98f23bb

Browse files
committed
feat: integrate theme management with theme presets and localStorage support in GuardianPanel
1 parent 6328952 commit 98f23bb

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/lib/components/panels/GuardianPanel.svelte

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { ChevronLeft, ChevronRight, User, Key, Settings, CheckCircle, AlertCircle, Terminal } from 'lucide-svelte';
55
import { guardianHelpers } from '$lib/stores/guardian.js';
66
import { aiAnalysisHelpers } from '$lib/stores/ai-analysis.js';
7+
import { loadThemePreset, themePresets } from '$lib/stores/theme.js';
78
89
let apiKeyInput = '';
910
let guardianName = '';
@@ -18,11 +19,13 @@
1819
1920
// CLI-style editing states
2021
let editingField: string | null = null;
21-
let themes = ['everforest', 'gruvbox', 'tokyo-night', 'nord'];
22-
let currentTheme = 'everforest';
22+
const themeKeys = Object.keys(themePresets) as Array<keyof typeof themePresets>;
23+
let currentThemeKey: keyof typeof themePresets = 'everforest';
2324
let themeIndex = 0;
2425
25-
onMount(() => {
26+
const displayKey = (k: keyof typeof themePresets) => (k === 'tokyoNight' ? 'tokyo-night' : k);
27+
28+
onMount(() => {
2629
// Load saved guardian data
2730
const saved = guardianHelpers.load();
2831
if (saved) {
@@ -31,23 +34,21 @@
3134
preferences = { ...preferences, ...saved.preferences };
3235
}
3336
34-
// Get current theme from document
35-
const savedTheme = localStorage.getItem('petalytics-theme') || 'everforest';
36-
currentTheme = savedTheme;
37-
themeIndex = themes.indexOf(savedTheme);
37+
// Get current theme from localStorage
38+
const savedTheme = (localStorage.getItem('petalytics-theme') as keyof typeof themePresets) || 'everforest';
39+
currentThemeKey = themeKeys.includes(savedTheme) ? savedTheme : 'everforest';
40+
themeIndex = themeKeys.indexOf(currentThemeKey);
3841
});
3942
4043
function toggleTheme(direction: 'prev' | 'next') {
4144
if (direction === 'next') {
42-
themeIndex = (themeIndex + 1) % themes.length;
45+
themeIndex = (themeIndex + 1) % themeKeys.length;
4346
} else {
44-
themeIndex = (themeIndex - 1 + themes.length) % themes.length;
47+
themeIndex = (themeIndex - 1 + themeKeys.length) % themeKeys.length;
4548
}
46-
currentTheme = themes[themeIndex];
47-
48-
// Apply theme
49-
document.documentElement.className = currentTheme;
50-
localStorage.setItem('petalytics-theme', currentTheme);
49+
currentThemeKey = themeKeys[themeIndex];
50+
// Apply via store (persists to localStorage and updates CSS vars)
51+
loadThemePreset(currentThemeKey);
5152
}
5253
5354
function togglePreference(key: keyof typeof preferences) {
@@ -197,7 +198,7 @@
197198
<div class="cli-row px-2 py-1">
198199
<span class="label" style="color: var(--petalytics-foam);">theme</span>
199200
<span class="value" style="color: var(--petalytics-text);">
200-
{currentTheme}
201+
{displayKey(currentThemeKey)}
201202
</span>
202203
<div class="ml-2 flex items-center space-x-1">
203204
<button type="button" class="arrow-btn" onclick={() => toggleTheme('prev')} aria-label="Previous theme">&lt;</button>

0 commit comments

Comments
 (0)