Skip to content

Commit

Permalink
fix: fix dark theme toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
anfibiacreativa committed Dec 6, 2023
1 parent 5bade00 commit d581f8a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ export type CustomStylesState = {

interface Props {
onChange: (newStyles: CustomStylesState) => void;
isDarkTheme: boolean;
}

export const SettingsStyles = ({ onChange, isDarkTheme }: Props) => {
export const SettingsStyles = ({ onChange }: Props) => {
// this needs to come from an API call to some config persisted in the DB
const styleDefaultsLight = {
AccentHighDefault: '#692b61',
Expand Down Expand Up @@ -47,8 +46,9 @@ export const SettingsStyles = ({ onChange, isDarkTheme }: Props) => {
};

const getInitialStyles = (): CustomStylesState => {
const styleDefaults = isDarkTheme ? styleDefaultsDark : styleDefaultsLight;
const storedStyles = localStorage.getItem('customStyles');
const themeStore = localStorage.getItem('isDarkTheme');
const styleDefaults = themeStore === 'true' ? styleDefaultsDark : styleDefaultsLight;
if (storedStyles === '') {
localStorage.setItem('customStyles', JSON.stringify(styleDefaults));
}
Expand Down
3 changes: 2 additions & 1 deletion packages/webapp/src/components/ThemeSwitch/ThemeSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export const ThemeSwitch: React.FC<ThemeSwitchProps> = ({ onToggle, isDarkTheme,
// Toggle 'dark' class on the shell app body element based on the isDarkTheme prop and isConfigPanelOpen
document.body.classList.toggle('dark', isDarkTheme);
document.documentElement.dataset.theme = isDarkTheme && isConfigPanelOpen ? 'dark' : '';
}, []);
localStorage.removeItem('isDarkTheme');
}, [isDarkTheme, isConfigPanelOpen]);

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/src/pages/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ const Chat = () => {
{isChatStylesAccordionOpen && (
<>
<TooltipHost calloutProps={toolTipTextCalloutProps} content={toolTipText.promptTemplate}>
<SettingsStyles onChange={handleCustomStylesChange} isDarkTheme={isDarkTheme}></SettingsStyles>
<SettingsStyles onChange={handleCustomStylesChange}></SettingsStyles>
</TooltipHost>
</>
)}
Expand Down

0 comments on commit d581f8a

Please sign in to comment.