diff --git a/app/components/Header/AuthModal.client.vue b/app/components/Header/AuthModal.client.vue index d12a8e528..76171a888 100644 --- a/app/components/Header/AuthModal.client.vue +++ b/app/components/Header/AuthModal.client.vue @@ -5,6 +5,37 @@ import { authRedirect } from '~/utils/atproto/helpers' const handleInput = shallowRef('') const route = useRoute() const { user, logout } = useAtproto() +const { settings } = useSettings() +const colorMode = useColorMode() +const { setLocale, locales, locale } = useI18n() + +//TODO need to check them all and idk if this is the spot for it +watch( + user, + async loggedInUser => { + if (!loggedInUser) return + + const remote = await $fetch('/api/auth/settings') + if (!remote) return + + Object.assign(settings.value, remote) + + // Sync theme with colorMode + if (remote.theme) { + colorMode.preference = remote.theme + } + + // Sync locale if it's valid and different from current + if ( + remote.selectedLocale && + remote.selectedLocale !== locale.value && + locales.value.map(l => l.code).includes(remote.selectedLocale) + ) { + setLocale(remote.selectedLocale) + } + }, + { immediate: true }, +) // https://atproto.com supports 4 locales as of 2026-02-07 const { locale } = useI18n() diff --git a/app/composables/useSettings.ts b/app/composables/useSettings.ts index 98c313957..80d5fb500 100644 --- a/app/composables/useSettings.ts +++ b/app/composables/useSettings.ts @@ -1,35 +1,11 @@ import type { RemovableRef } from '@vueuse/core' import { useLocalStorage } from '@vueuse/core' import { ACCENT_COLORS } from '#shared/utils/constants' -import type { LocaleObject } from '@nuxtjs/i18n' import { BACKGROUND_THEMES } from '#shared/utils/constants' - -type BackgroundThemeId = keyof typeof BACKGROUND_THEMES - -type AccentColorId = keyof typeof ACCENT_COLORS.light - -/** - * Application settings stored in localStorage - */ -export interface AppSettings { - /** Display dates as relative (e.g., "3 days ago") instead of absolute */ - relativeDates: boolean - /** Include @types/* package in install command for packages without built-in types */ - includeTypesInInstall: boolean - /** Accent color theme */ - accentColorId: AccentColorId | null - /** Preferred background shade */ - preferredBackgroundTheme: BackgroundThemeId | null - /** Hide platform-specific packages (e.g., @scope/pkg-linux-x64) from search results */ - hidePlatformPackages: boolean - /** User-selected locale */ - selectedLocale: LocaleObject['code'] | null - sidebar: { - collapsed: string[] - } -} +import type { AccentColorId, BackgroundThemeId, AppSettings } from '#shared/schemas/app-settings' const DEFAULT_SETTINGS: AppSettings = { + theme: 'system', relativeDates: false, includeTypesInInstall: true, accentColorId: null, @@ -41,6 +17,14 @@ const DEFAULT_SETTINGS: AppSettings = { }, } +export const syncSettings = async (settings: AppSettings) => { + // DO some error handling + await $fetch('/api/auth/settings', { + method: 'POST', + body: settings, + }) +} + const STORAGE_KEY = 'npmx-settings' // Shared settings instance (singleton per app) diff --git a/app/pages/settings.vue b/app/pages/settings.vue index 33e76be99..5ad5f1c9e 100644 --- a/app/pages/settings.vue +++ b/app/pages/settings.vue @@ -1,9 +1,11 @@