-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ui): Added theme profile to log-viewer #21448
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,65 @@ 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}) => ( | ||
<ToggleButton | ||
title='Dark Mode' | ||
onToggle={() => { | ||
const inverted = prefs.appDetails.darkMode; | ||
// Added a logviewer theme profile | ||
|
||
interface LogViewerTheme { | ||
light: boolean; | ||
dark: boolean; | ||
} | ||
|
||
export const DarkModeToggleButton = ({prefs}: {prefs: ViewPreferences}) => { | ||
React.useEffect(() => { | ||
const profiles = prefs.appDetails.LogViewerTheme as LogViewerTheme; | ||
const currentTheme = prefs.theme; | ||
|
||
if (!profiles) { | ||
services.viewPreferences.updatePreferences({ | ||
...prefs, | ||
appDetails: { | ||
...prefs.appDetails, | ||
LogViewerTheme: { | ||
light: false, | ||
dark: true | ||
}, | ||
darkMode: currentTheme === 'dark' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we duplicating the theme params here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 yes, there is duplication happening here as both darkMode and LogViewerTheme are controlling the state and used to update and store preferences, tried multiple ways to have the userpreference with the current darkMode controller without duplication coudn't get to a good solution without it, I am refactoring it with small change like using darkMode itself LogViewerTheme: { |
||
} | ||
}); | ||
return; | ||
} | ||
|
||
const profilePreference = currentTheme === 'dark' ? profiles.dark : profiles.light; | ||
if (prefs.appDetails.darkMode !== profilePreference) { | ||
services.viewPreferences.updatePreferences({ | ||
...prefs, | ||
appDetails: {...prefs.appDetails, darkMode: !inverted} | ||
appDetails: { | ||
...prefs.appDetails, | ||
darkMode: profilePreference | ||
} | ||
}); | ||
}} | ||
toggled={prefs.appDetails.darkMode} | ||
icon='moon' | ||
/> | ||
); | ||
} | ||
}, [prefs.theme]); | ||
|
||
const handleToggle = () => { | ||
const newDarkMode = !prefs.appDetails.darkMode; | ||
const currentTheme = prefs.theme; | ||
const profiles = (prefs.appDetails.LogViewerTheme as LogViewerTheme) || { | ||
light: false, | ||
dark: true | ||
}; | ||
|
||
services.viewPreferences.updatePreferences({ | ||
...prefs, | ||
appDetails: { | ||
...prefs.appDetails, | ||
darkMode: newDarkMode, | ||
LogViewerTheme: { | ||
...profiles, | ||
[currentTheme]: newDarkMode | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
return <ToggleButton title='Dark Mode' onToggle={handleToggle} toggled={prefs.appDetails.darkMode} icon='moon' />; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This data structure is strange to me. What would be the meaning of
{light: true, dark: true}
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the structure is really
where
light: false
means "don't use dark mode in log viewer when in light mode app theme" anddark: true
means "use dark mode in log viewer when in dark mode app theme".and
light: true
means "use dark mode in log viewer when in light mode app theme" anddark: false
means "use light mode in log viewer when in dark mode app theme".Those last two settings exist to enable users to hurt their eyes, but apparently they're desirable modes, so here we are :)
-- I can't think of a particularly better way to structure the thing, but...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, this is what it represent my naming wasn't quite right