11import type { RemovableRef } from '@vueuse/core'
22import { useLocalStorage } from '@vueuse/core'
33import { ACCENT_COLORS } from '#shared/utils/constants'
4- import type { LocaleObject } from '@nuxtjs/i18n'
54import { BACKGROUND_THEMES } from '#shared/utils/constants'
6-
7- type BackgroundThemeId = keyof typeof BACKGROUND_THEMES
8-
9- type AccentColorId = keyof typeof ACCENT_COLORS . light
10-
11- /**
12- * Application settings stored in localStorage
13- */
14- export interface AppSettings {
15- /** Display dates as relative (e.g., "3 days ago") instead of absolute */
16- relativeDates : boolean
17- /** Include @types/* package in install command for packages without built-in types */
18- includeTypesInInstall : boolean
19- /** Accent color theme */
20- accentColorId : AccentColorId | null
21- /** Preferred background shade */
22- preferredBackgroundTheme : BackgroundThemeId | null
23- /** Hide platform-specific packages (e.g., @scope/pkg-linux-x64) from search results */
24- hidePlatformPackages : boolean
25- /** User-selected locale */
26- selectedLocale : LocaleObject [ 'code' ] | null
27- sidebar : {
28- collapsed : string [ ]
29- }
30- }
5+ import type { AccentColorId , BackgroundThemeId , AppSettings } from '#shared/schemas/app-settings'
316
327const DEFAULT_SETTINGS : AppSettings = {
338 relativeDates : false ,
@@ -41,6 +16,14 @@ const DEFAULT_SETTINGS: AppSettings = {
4116 } ,
4217}
4318
19+ export const syncSettings = async ( settings : AppSettings ) => {
20+ // DO some error handling
21+ await $fetch ( '/api/auth/settings' , {
22+ method : 'POST' ,
23+ body : settings ,
24+ } )
25+ }
26+
4427const STORAGE_KEY = 'npmx-settings'
4528
4629// Shared settings instance (singleton per app)
@@ -133,6 +116,7 @@ export function useBackgroundTheme() {
133116 document . documentElement . removeAttribute ( 'data-bg-theme' )
134117 }
135118 settings . value . preferredBackgroundTheme = id
119+ syncSettings ( settings . value )
136120 }
137121
138122 return {
0 commit comments