Enhance DashboardNavigation Component with User Settings Integration

- Updated DashboardNavigation to utilize user settings for appearance and navigation label preferences, improving user experience.
- Introduced logic to dynamically set theme mode and density based on user preferences and application settings.
- Refactored useEffect to ensure settings are applied only when user settings are loaded, enhancing performance and reliability.
This commit is contained in:
Tom Butcher 2026-09-04 02:33:20 +01:00
parent 8b33a82a65
commit 8ff580bf0f

View File

@ -49,15 +49,22 @@ import {
import { useAppUpdateContext } from '../context/AppUpdateContext' import { useAppUpdateContext } from '../context/AppUpdateContext'
import { useThemeContext } from '../context/ThemeContext' import { useThemeContext } from '../context/ThemeContext'
import { getEffectiveAppearance } from '../../../database/Settings'
const { Text } = Typography const { Text } = Typography
const DashboardNavigation = () => { const DashboardNavigation = () => {
const { userProfile } = useContext(AuthContext) const { userProfile } = useContext(AuthContext)
const { showSpotlight } = useContext(SpotlightContext) const { showSpotlight } = useContext(SpotlightContext)
const { connecting, connected } = useContext(ApiServerContext) const { connecting, connected, userSettings, userSettingsLoaded } =
useContext(ApiServerContext)
const { authenticated } = useContext(AuthContext) const { authenticated } = useContext(AuthContext)
const { showNavigationLabels, setShowNavigationLabels } = useThemeContext() const {
showNavigationLabels,
setShowNavigationLabels,
setThemeMode,
setDensityMode
} = useThemeContext()
const { toggleNotificationCenter, unreadCount } = const { toggleNotificationCenter, unreadCount } =
useContext(NotificationContext) useContext(NotificationContext)
const [apiServerState, setApiServerState] = useState('disconnected') const [apiServerState, setApiServerState] = useState('disconnected')
@ -81,21 +88,31 @@ const DashboardNavigation = () => {
const { availableUpdate, checkForUpdates } = useAppUpdateContext() const { availableUpdate, checkForUpdates } = useAppUpdateContext()
useEffect(() => { useEffect(() => {
const hydrateNavigationLabels = async () => { if (!userSettingsLoaded) return
const settings = isElectron
? await getAppSettings() const hydrateAppearance = async () => {
: userProfile?.settings || {} const electronSettings = isElectron ? await getAppSettings() : {}
if (settings?.showNavigationLabels !== undefined) { const effective = getEffectiveAppearance({
setShowNavigationLabels(settings.showNavigationLabels) isElectron,
userAppearance: userSettings?.appearance || {},
electronSettings
})
if (effective.theme) setThemeMode(effective.theme)
if (effective.density) setDensityMode(effective.density)
if (effective.showNavigationLabels !== undefined) {
setShowNavigationLabels(effective.showNavigationLabels)
} }
} }
void hydrateNavigationLabels() void hydrateAppearance()
}, [ }, [
getAppSettings, getAppSettings,
isElectron, isElectron,
setDensityMode,
setShowNavigationLabels, setShowNavigationLabels,
userProfile?.settings setThemeMode,
userSettings?.appearance,
userSettingsLoaded
]) ])
const includeDev = import.meta.env.DEV const includeDev = import.meta.env.DEV