diff --git a/ui/src/app/applications/components/pod-logs-viewer/dark-mode-toggle-button.tsx b/ui/src/app/applications/components/pod-logs-viewer/dark-mode-toggle-button.tsx index cd93a728ef5a8..59aba01fd1807 100644 --- a/ui/src/app/applications/components/pod-logs-viewer/dark-mode-toggle-button.tsx +++ b/ui/src/app/applications/components/pod-logs-viewer/dark-mode-toggle-button.tsx @@ -3,17 +3,60 @@ import * as React from 'react'; import {ToggleButton} from '../../../shared/components/toggle-button'; // DarkModeToggleButton is a component that renders a toggle button that toggles dark mode. -export const DarkModeToggleButton = ({prefs}: {prefs: ViewPreferences}) => ( - { - const inverted = prefs.appDetails.darkMode; +// Added a logviewer theme profile + +export const DarkModeToggleButton = ({prefs}: {prefs: ViewPreferences}) => { + React.useEffect(() => { + // Only run when theme changes or LogViewerTheme is not initialized + const profile = prefs.appDetails.UseDarkModeInLogViewerForAppTheme; + + if (!profile) { + // First time initialization services.viewPreferences.updatePreferences({ ...prefs, - appDetails: {...prefs.appDetails, darkMode: !inverted} + appDetails: { + ...prefs.appDetails, + UseDarkModeInLogViewerForAppTheme: { + light: prefs.appDetails.darkMode, + dark: prefs.appDetails.darkMode + } + } }); - }} - toggled={prefs.appDetails.darkMode} - icon='moon' - /> -); + return; + } + + // Update darkMode based on saved preference for current theme + const currentThemeDarkMode = profile[prefs.theme as keyof typeof profile]; + if (prefs.appDetails.darkMode !== currentThemeDarkMode) { + services.viewPreferences.updatePreferences({ + ...prefs, + appDetails: { + ...prefs.appDetails, + darkMode: currentThemeDarkMode + } + }); + } + }, [prefs.theme]); + + const handleToggle = () => { + const newDarkMode = !prefs.appDetails.darkMode; + const currentProfile = prefs.appDetails.UseDarkModeInLogViewerForAppTheme || { + light: prefs.appDetails.darkMode, + dark: prefs.appDetails.darkMode + }; + + services.viewPreferences.updatePreferences({ + ...prefs, + appDetails: { + ...prefs.appDetails, + darkMode: newDarkMode, + UseDarkModeInLogViewerForAppTheme: { + ...currentProfile, + [prefs.theme]: newDarkMode + } + } + }); + }; + + return ; +}; diff --git a/ui/src/app/shared/services/view-preferences-service.ts b/ui/src/app/shared/services/view-preferences-service.ts index 575c4b734d416..baf0e91552d86 100644 --- a/ui/src/app/shared/services/view-preferences-service.ts +++ b/ui/src/app/shared/services/view-preferences-service.ts @@ -31,6 +31,7 @@ export interface AppDetailsPreferences { zoom: number; podGroupCount: number; userHelpTipMsgs: UserMessages[]; + UseDarkModeInLogViewerForAppTheme?: {light: boolean; dark: boolean}; } export interface PodViewPreferences {