Skip to content

Commit

Permalink
fix: Custom theme is reset to default theme after refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
yinxin630 committed Oct 24, 2019
1 parent 79eb368 commit f8d976b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions client/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function getData() {
primaryColor: '',
primaryTextColor: '',
backgroundImage: '',
zero: false,
aero: false,
};
if (theme && config.theme[theme]) {
themeConfig = config.theme[theme];
Expand All @@ -62,7 +62,7 @@ export default function getData() {
LocalStorageKey.BackgroundImage,
config.theme.default.backgroundImage,
),
zero: getSwitchValue(
aero: getSwitchValue(
LocalStorageKey.Aero,
false,
),
Expand Down
2 changes: 1 addition & 1 deletion client/modules/Chat/Chat.less
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
position: relative;

&[data-aero=true] {
background-color: rgba(241, 241, 241, 0.1);
background-color: rgba(241, 241, 241, 0.15);
}

@media @mobile {
Expand Down
14 changes: 10 additions & 4 deletions client/modules/Sidebar/Setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import playSound from '../../../utils/playSound';
import Style from './Setting.less';
import Common from './Common.less';
import { Tabs, TabPane, ScrollableInkTabBar, TabContent } from '../../components/Tabs';
import { LocalStorageKey } from '../../localStorage';

interface SettingProps {
visible: boolean;
Expand Down Expand Up @@ -52,11 +53,16 @@ function Setting(props: SettingProps) {
action.setStatus('backgroundImage', themeConfig.backgroundImage);
action.setStatus('aero', themeConfig.aero);
setCssVariable(themeConfig.primaryColor, themeConfig.primaryTextColor);
window.localStorage.removeItem('primaryColor');
window.localStorage.removeItem('primaryTextColor');
window.localStorage.removeItem('backgroundImage');
window.localStorage.removeItem('zero');
window.localStorage.removeItem(LocalStorageKey.PrimaryColor);
window.localStorage.removeItem(LocalStorageKey.PrimaryTextColor);
window.localStorage.removeItem(LocalStorageKey.BackgroundImage);
window.localStorage.removeItem(LocalStorageKey.Aero);
Message.success('已修改主题');
} else {
window.localStorage.setItem(LocalStorageKey.PrimaryColor, primaryColor);
window.localStorage.setItem(LocalStorageKey.PrimaryTextColor, primaryTextColor);
window.localStorage.setItem(LocalStorageKey.BackgroundImage, backgroundImage);
window.localStorage.setItem(LocalStorageKey.Aero, aero.toString());
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/state/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ const initialState: State = {
primaryColor: localStorage.primaryColor,
primaryTextColor: localStorage.primaryTextColor,
backgroundImage: localStorage.backgroundImage,
aero: false,
aero: localStorage.aero,
soundSwitch: localStorage.soundSwitch,
sound: localStorage.sound,
notificationSwitch: localStorage.notificationSwitch,
Expand Down

0 comments on commit f8d976b

Please sign in to comment.