|
4 | 4 | import { ChevronLeft, ChevronRight, User, Key, Settings, CheckCircle, AlertCircle, Terminal } from 'lucide-svelte'; |
5 | 5 | import { guardianHelpers } from '$lib/stores/guardian.js'; |
6 | 6 | import { aiAnalysisHelpers } from '$lib/stores/ai-analysis.js'; |
| 7 | + import { loadThemePreset, themePresets } from '$lib/stores/theme.js'; |
7 | 8 |
|
8 | 9 | let apiKeyInput = ''; |
9 | 10 | let guardianName = ''; |
|
18 | 19 | |
19 | 20 | // CLI-style editing states |
20 | 21 | 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'; |
23 | 24 | let themeIndex = 0; |
24 | 25 |
|
25 | | - onMount(() => { |
| 26 | + const displayKey = (k: keyof typeof themePresets) => (k === 'tokyoNight' ? 'tokyo-night' : k); |
| 27 | +
|
| 28 | + onMount(() => { |
26 | 29 | // Load saved guardian data |
27 | 30 | const saved = guardianHelpers.load(); |
28 | 31 | if (saved) { |
|
31 | 34 | preferences = { ...preferences, ...saved.preferences }; |
32 | 35 | } |
33 | 36 | |
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); |
38 | 41 | }); |
39 | 42 |
|
40 | 43 | function toggleTheme(direction: 'prev' | 'next') { |
41 | 44 | if (direction === 'next') { |
42 | | - themeIndex = (themeIndex + 1) % themes.length; |
| 45 | + themeIndex = (themeIndex + 1) % themeKeys.length; |
43 | 46 | } else { |
44 | | - themeIndex = (themeIndex - 1 + themes.length) % themes.length; |
| 47 | + themeIndex = (themeIndex - 1 + themeKeys.length) % themeKeys.length; |
45 | 48 | } |
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); |
51 | 52 | } |
52 | 53 |
|
53 | 54 | function togglePreference(key: keyof typeof preferences) { |
|
197 | 198 | <div class="cli-row px-2 py-1"> |
198 | 199 | <span class="label" style="color: var(--petalytics-foam);">theme</span> |
199 | 200 | <span class="value" style="color: var(--petalytics-text);"> |
200 | | - {currentTheme} |
| 201 | + {displayKey(currentThemeKey)} |
201 | 202 | </span> |
202 | 203 | <div class="ml-2 flex items-center space-x-1"> |
203 | 204 | <button type="button" class="arrow-btn" onclick={() => toggleTheme('prev')} aria-label="Previous theme"><</button> |
|
0 commit comments