Skip to content

Commit 7881d2f

Browse files
committed
fix: revert all changes to accent color modules
1 parent 05db2f4 commit 7881d2f

File tree

5 files changed

+44
-52
lines changed

5 files changed

+44
-52
lines changed

app/components/Settings/AccentColorPicker.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<script setup lang="ts">
22
import { useAccentColor } from '~/composables/useSettings'
33
4-
const { accentColors, selectedAccentColorOptionId, setAccentColor } = useAccentColor()
4+
const { accentColors, selectedAccentColor, setAccentColor } = useAccentColor()
55
66
onPrehydrate(el => {
77
const settings = JSON.parse(localStorage.getItem('npmx-settings') || '{}')
88
// Hardcoded — onPrehydrate is serialized into a <script> tag and cannot reference imports
99
const defaultId = 'sky'
10-
const id = settings.accentColorId ?? defaultId
10+
const id = settings.accentColorId
1111
if (id) {
1212
const input = el.querySelector<HTMLInputElement>(`input[value="${id}"]`)
1313
if (input) {
@@ -43,7 +43,7 @@ onPrehydrate(el => {
4343
name="accent-color"
4444
class="sr-only"
4545
:value="color.id"
46-
:checked="selectedAccentColorOptionId === color.id"
46+
:checked="selectedAccentColor === color.id || (!selectedAccentColor && color.id === 'sky')"
4747
:aria-label="color.label"
4848
@change="setAccentColor(color.id)"
4949
/>

app/components/Settings/BgThemePicker.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<script setup lang="ts">
2-
const { backgroundThemes, selectedBackgroundThemeOptionId, setBackgroundTheme } =
3-
useBackgroundTheme()
2+
const { backgroundThemes, selectedBackgroundTheme, setBackgroundTheme } = useBackgroundTheme()
43
54
onPrehydrate(el => {
65
const settings = JSON.parse(localStorage.getItem('npmx-settings') || '{}')
76
// Hardcoded — onPrehydrate is serialized into a <script> tag and cannot reference imports
87
const defaultId = 'neutral'
9-
const id = settings.preferredBackgroundTheme ?? defaultId
8+
const id = settings.preferredBackgroundTheme
109
if (id) {
1110
const input = el.querySelector<HTMLInputElement>(`input[value="${id}"]`)
1211
if (input) {
@@ -41,7 +40,10 @@ onPrehydrate(el => {
4140
name="background-theme"
4241
class="sr-only"
4342
:value="theme.id"
44-
:checked="selectedBackgroundThemeOptionId === theme.id"
43+
:checked="
44+
selectedBackgroundTheme === theme.id ||
45+
(!selectedBackgroundTheme && theme.id === 'neutral')
46+
"
4547
:aria-label="theme.label"
4648
@change="setBackgroundTheme(theme.id)"
4749
/>

app/composables/useCommandPaletteGlobalCommands.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ export function useCommandPaletteGlobalCommands() {
7373
const { locale, locales, setLocale, t } = useI18n()
7474
const route = useRoute()
7575
const colorMode = useColorMode()
76-
const { accentColors, selectedAccentColorOptionId, setAccentColor } = useAccentColor()
77-
const { backgroundThemes, selectedBackgroundThemeOptionId, setBackgroundTheme } =
78-
useBackgroundTheme()
76+
const { accentColors, selectedAccentColor, setAccentColor } = useAccentColor()
77+
const { backgroundThemes, selectedBackgroundTheme, setBackgroundTheme } = useBackgroundTheme()
7978
const connectorModal = useModal('connector-modal')
8079
const authModal = useModal('auth-modal')
8180
const keyboardShortcutsModal = useModal('keyboard-shortcuts-modal')
@@ -108,28 +107,25 @@ export function useCommandPaletteGlobalCommands() {
108107
return typeof current === 'string' ? current : (current.name ?? current.code)
109108
})
110109
const currentAccentColorLabel = computed(() => {
111-
const activeAccentColorId = selectedAccentColorOptionId.value
112-
const activeAccentColor = accentColors.value.find(color => color.id === activeAccentColorId)
113-
114-
if (!activeAccentColor) return activeAccentColorId
115-
return activeAccentColor.id === 'neutral'
116-
? t('settings.accent_colors.neutral')
117-
: activeAccentColor.label
110+
const id = selectedAccentColor.value
111+
if (!id) return t('settings.accent_colors.neutral')
112+
const color = accentColors.value.find(c => c.id === id)
113+
return color?.label ?? id
118114
})
119115
const currentAccentColorPreview = computed(() => {
120-
const activeAccentColorId = selectedAccentColorOptionId.value
121-
return accentColors.value.find(color => color.id === activeAccentColorId)?.value ?? null
116+
const id = selectedAccentColor.value
117+
if (!id) return null
118+
return accentColors.value.find(c => c.id === id)?.value ?? null
122119
})
123120
const currentBackgroundThemeLabel = computed(() => {
124-
const activeBackgroundThemeId = selectedBackgroundThemeOptionId.value
125-
return (
126-
backgroundThemes.value.find(theme => theme.id === activeBackgroundThemeId)?.label ??
127-
activeBackgroundThemeId
128-
)
121+
const id = selectedBackgroundTheme.value
122+
if (!id) return t('settings.background_themes.neutral')
123+
return backgroundThemes.value.find(t => t.id === id)?.label ?? id
129124
})
130125
const currentBackgroundThemePreview = computed(() => {
131-
const activeBackgroundThemeId = selectedBackgroundThemeOptionId.value
132-
return backgroundThemes.value.find(theme => theme.id === activeBackgroundThemeId)?.value ?? null
126+
const id = selectedBackgroundTheme.value
127+
if (!id) return null
128+
return backgroundThemes.value.find(t => t.id === id)?.value ?? null
133129
})
134130
const localeCommands = computed<CommandPaletteCommand[]>(() =>
135131
locales.value.map(entry => {
@@ -159,7 +155,7 @@ export function useCommandPaletteGlobalCommands() {
159155
}),
160156
)
161157
const accentColorCommands = computed<CommandPaletteCommand[]>(() => {
162-
const activeAccentColorId = selectedAccentColorOptionId.value
158+
const activeId = selectedAccentColor.value
163159

164160
return accentColors.value.map(color => ({
165161
id: `accent-color:${color.id}`,
@@ -168,11 +164,13 @@ export function useCommandPaletteGlobalCommands() {
168164
keywords: [color.label, color.id, t('settings.accent_colors.label'), t('settings.theme')],
169165
iconClass: 'i-lucide:palette',
170166
previewColor: color.value,
171-
active: color.id === activeAccentColorId,
172-
activeLabel: color.id === activeAccentColorId ? t('command_palette.current') : null,
167+
active: color.id === 'neutral' ? !activeId : color.id === activeId,
168+
activeLabel: (color.id === 'neutral' ? !activeId : color.id === activeId)
169+
? t('command_palette.current')
170+
: null,
173171
action: runThenAnnounce(
174172
() => {
175-
setAccentColor(color.id)
173+
setAccentColor(color.id === 'neutral' ? null : color.id)
176174
},
177175
() =>
178176
t('command_palette.announcements.accent_color_changed', {
@@ -182,7 +180,7 @@ export function useCommandPaletteGlobalCommands() {
182180
}))
183181
})
184182
const backgroundThemeCommands = computed<CommandPaletteCommand[]>(() => {
185-
const activeBackgroundThemeId = selectedBackgroundThemeOptionId.value
183+
const activeId = selectedBackgroundTheme.value
186184

187185
return backgroundThemes.value.map(theme => ({
188186
id: `background-theme:${theme.id}`,
@@ -191,8 +189,10 @@ export function useCommandPaletteGlobalCommands() {
191189
keywords: [theme.label, theme.id, t('settings.background_themes.label'), t('settings.theme')],
192190
iconClass: 'i-lucide:swatch-book',
193191
previewColor: theme.value,
194-
active: theme.id === activeBackgroundThemeId,
195-
activeLabel: theme.id === activeBackgroundThemeId ? t('command_palette.current') : null,
192+
active: theme.id === 'neutral' ? !activeId : theme.id === activeId,
193+
activeLabel: (theme.id === 'neutral' ? !activeId : theme.id === activeId)
194+
? t('command_palette.current')
195+
: null,
196196
action: runThenAnnounce(
197197
() => {
198198
setBackgroundTheme(theme.id)

app/composables/useSettings.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ const DEFAULT_SETTINGS: AppSettings = {
7676
},
7777
}
7878

79-
export const DEFAULT_ACCENT_COLOR_ID = DEFAULT_SETTINGS.accentColorId
80-
export const DEFAULT_BACKGROUND_THEME_ID = DEFAULT_SETTINGS.preferredBackgroundTheme
81-
export const DEFAULT_ACCENT_COLOR_OPTION_ID: AccentColorId = DEFAULT_ACCENT_COLOR_ID ?? 'sky'
82-
export const DEFAULT_BACKGROUND_THEME_OPTION_ID: BackgroundThemeId =
83-
DEFAULT_BACKGROUND_THEME_ID ?? 'neutral'
84-
8579
const STORAGE_KEY = 'npmx-settings'
8680

8781
// Shared settings instance (singleton per app)
@@ -167,22 +161,17 @@ export function useAccentColor() {
167161
})
168162

169163
function setAccentColor(id: AccentColorId | null) {
170-
const accentColorId = id === 'neutral' ? DEFAULT_ACCENT_COLOR_ID : id
171-
172-
if (accentColorId) {
173-
document.documentElement.style.setProperty('--accent-color', `var(--swatch-${accentColorId})`)
164+
if (id) {
165+
document.documentElement.style.setProperty('--accent-color', `var(--swatch-${id})`)
174166
} else {
175167
document.documentElement.style.removeProperty('--accent-color')
176168
}
177-
settings.value.accentColorId = accentColorId
169+
settings.value.accentColorId = id
178170
}
179171

180172
return {
181173
accentColors,
182174
selectedAccentColor: computed(() => settings.value.accentColorId),
183-
selectedAccentColorOptionId: computed(
184-
() => settings.value.accentColorId ?? DEFAULT_ACCENT_COLOR_OPTION_ID,
185-
),
186175
setAccentColor,
187176
}
188177
}
@@ -246,9 +235,6 @@ export function useBackgroundTheme() {
246235
return {
247236
backgroundThemes,
248237
selectedBackgroundTheme: computed(() => settings.value.preferredBackgroundTheme),
249-
selectedBackgroundThemeOptionId: computed(
250-
() => settings.value.preferredBackgroundTheme ?? DEFAULT_BACKGROUND_THEME_OPTION_ID,
251-
),
252238
setBackgroundTheme,
253239
}
254240
}

test/nuxt/composables/use-command-palette-commands.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ describe('useCommandPaletteCommands', () => {
164164
expect(flatCommands.value.find(command => command.id === 'settings')?.label).toBe('settings')
165165
expect(flatCommands.value.find(command => command.id === 'theme-system')?.active).toBe(true)
166166
expect(flatCommands.value.find(command => command.id === 'theme-dark')).toBeTruthy()
167-
expect(flatCommands.value.find(command => command.id === 'accent-colors')?.badge).toBe('Sky')
167+
expect(flatCommands.value.find(command => command.id === 'accent-colors')?.badge).toBe(
168+
'Neutral',
169+
)
168170
expect(flatCommands.value.find(command => command.id === 'background-themes')?.badge).toBe(
169171
'Neutral',
170172
)
@@ -439,7 +441,9 @@ describe('useCommandPaletteCommands', () => {
439441
})
440442

441443
expect(groupedCommands.value.map(group => group.id)).toEqual(['settings'])
442-
expect(flatCommands.value.find(command => command.id === 'accent-color:sky')?.active).toBe(true)
444+
expect(flatCommands.value.find(command => command.id === 'accent-color:neutral')?.active).toBe(
445+
true,
446+
)
443447
expect(flatCommands.value.find(command => command.id === 'accent-color:coral')).toBeTruthy()
444448

445449
wrapper.unmount()

0 commit comments

Comments
 (0)