Fix language setting not being saved to database on admin settings page

- Added default_language field to general settings state in SettingsPage
- Replaced LanguageSelector component with simple select dropdown on settings page
- Fixed public settings endpoint to read general_default_language from database
- Language setting now properly saved when clicking Save Settings button
- Setting is correctly used by gallery login page and legal pages

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-07-08 09:49:45 +02:00
parent cfa0b0da69
commit 2012b0bab9
91 changed files with 6183 additions and 577 deletions
+50 -30
View File
@@ -1,4 +1,4 @@
import React, { createContext, useContext, useState, useEffect } from 'react';
import React, { createContext, useContext, useState, useEffect, useCallback, useMemo } from 'react';
import type { ReactNode } from 'react';
export interface ThemeConfig {
@@ -107,7 +107,7 @@ export const ThemeProvider: React.FC<ThemeProviderProps> = ({
const [theme, setTheme] = useState<ThemeConfig>(initialTheme);
const [themeName, setThemeName] = useState(initialThemeName);
const applyTheme = (themeConfig: ThemeConfig) => {
const applyTheme = useCallback((themeConfig: ThemeConfig) => {
const root = document.documentElement;
// Apply CSS variables
@@ -154,56 +154,76 @@ export const ThemeProvider: React.FC<ThemeProviderProps> = ({
}
styleElement.textContent = themeConfig.customCss;
}
};
}, []);
const setThemeByName = (name: string) => {
const setThemeConfig = useCallback((newTheme: ThemeConfig) => {
setTheme(newTheme);
applyTheme(newTheme);
}, [applyTheme]);
const setThemeByName = useCallback((name: string) => {
const presetTheme = PRESET_THEMES[name];
if (presetTheme) {
setThemeName(name);
setTheme(presetTheme.config);
applyTheme(presetTheme.config);
}
};
}, [applyTheme]);
const resetTheme = () => {
const resetTheme = useCallback(() => {
setThemeByName('default');
};
}, [setThemeByName]);
// Apply theme when it changes, but skip if it's the same
useEffect(() => {
applyTheme(theme);
}, [theme]);
const root = document.documentElement;
const currentPrimary = root.style.getPropertyValue('--color-primary');
// Only apply if the theme has actually changed
if (currentPrimary !== theme.primaryColor) {
applyTheme(theme);
}
}, [theme, applyTheme]);
// Load theme from localStorage on mount
// Load theme from localStorage on mount (skip if in gallery view)
useEffect(() => {
const savedTheme = localStorage.getItem('gallery-theme');
if (savedTheme) {
try {
const parsed = JSON.parse(savedTheme);
setTheme(parsed.config);
setThemeName(parsed.name);
} catch (e) {
console.error('Failed to load saved theme:', e);
// Check if we're in a gallery view by looking at the URL
const isGalleryView = window.location.pathname.includes('/gallery/');
if (!isGalleryView) {
const savedTheme = localStorage.getItem('gallery-theme');
if (savedTheme) {
try {
const parsed = JSON.parse(savedTheme);
setTheme(parsed.config);
setThemeName(parsed.name);
} catch (e) {
console.error('Failed to load saved theme:', e);
}
}
}
}, []);
// Save theme to localStorage when it changes
useEffect(() => {
localStorage.setItem('gallery-theme', JSON.stringify({ name: themeName, config: theme }));
// Only save if theme has actually changed
const currentSaved = localStorage.getItem('gallery-theme');
const newValue = JSON.stringify({ name: themeName, config: theme });
if (currentSaved !== newValue) {
localStorage.setItem('gallery-theme', newValue);
}
}, [theme, themeName]);
const contextValue = useMemo(() => ({
theme,
themeName,
setTheme: setThemeConfig,
setThemeByName,
applyTheme,
resetTheme
}), [theme, themeName, setThemeConfig, setThemeByName, applyTheme, resetTheme]);
return (
<ThemeContext.Provider value={{
theme,
themeName,
setTheme: (newTheme) => {
setTheme(newTheme);
applyTheme(newTheme);
},
setThemeByName,
applyTheme,
resetTheme
}}>
<ThemeContext.Provider value={contextValue}>
{children}
</ThemeContext.Provider>
);