feat: persist user preferences to database

This commit is contained in:
Clemens 2025-11-12 21:32:57 +01:00
parent 7ac5913c86
commit 60ac63604f
17 changed files with 271 additions and 17 deletions

View file

@ -1,5 +1,12 @@
import { getItem, setItem, removeItem } from '@/lib/storage';
import { AUTH_TOKEN } from './constants';
import {
AUTH_TOKEN,
LOCALE_CONFIG,
TIMEZONE_CONFIG,
DATE_RANGE_CONFIG,
THEME_CONFIG,
} from './constants';
import { setLocale, setTimezone, setDateRangeValue } from '@/store/app';
export function getClientAuthToken() {
return getItem(AUTH_TOKEN);
@ -12,3 +19,53 @@ export function setClientAuthToken(token: string) {
export function removeClientAuthToken() {
removeItem(AUTH_TOKEN);
}
export function setClientPreferences(preferences: {
dateRange?: string | null;
timezone?: string | null;
language?: string | null;
theme?: string | null;
}) {
const { dateRange, timezone, language, theme } = preferences;
if (dateRange !== undefined) {
if (dateRange === null) {
removeItem(DATE_RANGE_CONFIG);
} else {
setItem(DATE_RANGE_CONFIG, dateRange);
setDateRangeValue(dateRange);
}
}
if (timezone !== undefined) {
if (timezone === null) {
removeItem(TIMEZONE_CONFIG);
} else {
setItem(TIMEZONE_CONFIG, timezone);
setTimezone(timezone);
}
}
if (language !== undefined) {
if (language === null) {
removeItem(LOCALE_CONFIG);
} else {
setItem(LOCALE_CONFIG, language);
setLocale(language);
}
}
if (theme !== undefined) {
if (theme === null) {
removeItem(THEME_CONFIG);
} else {
setItem(THEME_CONFIG, theme);
}
}
}
export function removeClientPreferences() {
removeItem(DATE_RANGE_CONFIG);
removeItem(TIMEZONE_CONFIG);
removeItem(THEME_CONFIG);
}

View file

@ -3,7 +3,7 @@ export const AUTH_TOKEN = 'umami.auth';
export const LOCALE_CONFIG = 'umami.locale';
export const TIMEZONE_CONFIG = 'umami.timezone';
export const DATE_RANGE_CONFIG = 'umami.date-range';
export const THEME_CONFIG = 'umami.theme';
export const THEME_CONFIG = 'zen.theme';
export const DASHBOARD_CONFIG = 'umami.dashboard';
export const VERSION_CHECK = 'umami.version-check';
export const SHARE_TOKEN_HEADER = 'x-umami-share-token';