fix(portal): remember theme choice and restore light as default
Stop the one-time force-dark migration from overriding users, default first visits to light, and roll forced-dark browsers back to light once. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+22
-3
@@ -2,19 +2,37 @@ export type MemindTheme = 'light' | 'dark';
|
||||
|
||||
export const THEME_STORAGE_KEY = 'memind-theme';
|
||||
export const THEME_MIGRATION_KEY = 'memind-theme-migration';
|
||||
export const THEME_MIGRATION_VERSION = 'dark-default-2026-09-11';
|
||||
export const THEME_MIGRATION_VERSION = 'light-default-2026-09-12';
|
||||
export const DEFAULT_THEME: MemindTheme = 'light';
|
||||
|
||||
const FORCE_DARK_MIGRATION_VERSION = 'dark-default-2026-09-11';
|
||||
|
||||
const THEME_COLOR = {
|
||||
light: '#f4f1ea',
|
||||
dark: '#0f1419',
|
||||
} as const;
|
||||
|
||||
function syncThemeColor(theme: MemindTheme) {
|
||||
const meta = document.querySelector('meta[name="theme-color"]');
|
||||
if (meta) meta.setAttribute('content', THEME_COLOR[theme]);
|
||||
}
|
||||
|
||||
export function migrateThemePreferenceIfNeeded() {
|
||||
if (typeof localStorage === 'undefined') return;
|
||||
if (localStorage.getItem(THEME_MIGRATION_KEY) === THEME_MIGRATION_VERSION) return;
|
||||
localStorage.setItem(THEME_STORAGE_KEY, 'dark');
|
||||
const previousMigration = localStorage.getItem(THEME_MIGRATION_KEY);
|
||||
const stored = localStorage.getItem(THEME_STORAGE_KEY);
|
||||
if (previousMigration === FORCE_DARK_MIGRATION_VERSION && stored !== 'light') {
|
||||
localStorage.setItem(THEME_STORAGE_KEY, 'light');
|
||||
}
|
||||
localStorage.setItem(THEME_MIGRATION_KEY, THEME_MIGRATION_VERSION);
|
||||
}
|
||||
|
||||
export function getStoredTheme(): MemindTheme {
|
||||
if (typeof localStorage === 'undefined') return DEFAULT_THEME;
|
||||
const stored = localStorage.getItem(THEME_STORAGE_KEY);
|
||||
if (stored === 'dark' || stored === 'light') return stored;
|
||||
return 'dark';
|
||||
return DEFAULT_THEME;
|
||||
}
|
||||
|
||||
export function applyTheme(theme: MemindTheme) {
|
||||
@@ -22,6 +40,7 @@ export function applyTheme(theme: MemindTheme) {
|
||||
document.documentElement.dataset.theme = normalized;
|
||||
document.documentElement.style.colorScheme = normalized;
|
||||
localStorage.setItem(THEME_STORAGE_KEY, normalized);
|
||||
syncThemeColor(normalized);
|
||||
window.dispatchEvent(new CustomEvent('memind-theme-change', { detail: { theme: normalized } }));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user