feat(fe/settings): add theme preference
This commit is contained in:
parent
01e07273a6
commit
18aa61a0f8
11 changed files with 75 additions and 10 deletions
|
@ -27,6 +27,7 @@ export interface Preferences {
|
||||||
cssURL: string;
|
cssURL: string;
|
||||||
lanPackURL: string;
|
lanPackURL: string;
|
||||||
lan: string;
|
lan: string;
|
||||||
|
theme: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
|
|
|
@ -93,6 +93,7 @@ export const resps = {
|
||||||
cssURL: "cssURL",
|
cssURL: "cssURL",
|
||||||
lanPackURL: "lanPackURL",
|
lanPackURL: "lanPackURL",
|
||||||
lan: "en_US",
|
lan: "en_US",
|
||||||
|
theme: "light",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -97,6 +97,7 @@ describe("Login", () => {
|
||||||
cssURL: "cssURL",
|
cssURL: "cssURL",
|
||||||
lanPackURL: "lanPackURL",
|
lanPackURL: "lanPackURL",
|
||||||
lan: "en_US",
|
lan: "en_US",
|
||||||
|
theme: "light",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -113,6 +113,7 @@ describe("State Manager", () => {
|
||||||
cssURL: "cssURL",
|
cssURL: "cssURL",
|
||||||
lanPackURL: "lanPackURL",
|
lanPackURL: "lanPackURL",
|
||||||
lan: "en_US",
|
lan: "en_US",
|
||||||
|
theme: "light",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -329,6 +330,7 @@ describe("State Manager", () => {
|
||||||
cssURL: "",
|
cssURL: "",
|
||||||
lanPackURL: "",
|
lanPackURL: "",
|
||||||
lan: "en_US",
|
lan: "en_US",
|
||||||
|
theme: "light",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,7 @@ describe("TopBar", () => {
|
||||||
cssURL: "",
|
cssURL: "",
|
||||||
lanPackURL: "",
|
lanPackURL: "",
|
||||||
lan: "en_US",
|
lan: "en_US",
|
||||||
|
theme: "light",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ export function newState(): ICoreState {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function initState(): ICoreState {
|
export function initState(): ICoreState {
|
||||||
const defaultLanPackage = MsgPackage.get("en_US")
|
const defaultLanPackage = MsgPackage.get("en_US");
|
||||||
const filesOrderBy = defaultLanPackage.get("item.name");
|
const filesOrderBy = defaultLanPackage.get("item.name");
|
||||||
const uploadingsOrderBy = defaultLanPackage.get("item.path");
|
const uploadingsOrderBy = defaultLanPackage.get("item.path");
|
||||||
const sharingsOrderBy = defaultLanPackage.get("item.path");
|
const sharingsOrderBy = defaultLanPackage.get("item.path");
|
||||||
|
@ -107,6 +107,7 @@ export function initState(): ICoreState {
|
||||||
cssURL: "",
|
cssURL: "",
|
||||||
lanPackURL: "",
|
lanPackURL: "",
|
||||||
lan: "en_US",
|
lan: "en_US",
|
||||||
|
theme: "light",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
msg: {
|
msg: {
|
||||||
|
|
|
@ -156,6 +156,19 @@ export class PaneSettings extends React.Component<Props, State, {}> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
setTheme = async (theme: string) => {
|
||||||
|
updater().setTheme(theme);
|
||||||
|
try {
|
||||||
|
const status = await updater().syncPreferences();
|
||||||
|
if (status !== "") {
|
||||||
|
alertMsg(this.props.msg.pkg.get("update.fail"));
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
alertMsg(this.props.msg.pkg.get("update.ok"));
|
||||||
|
this.props.update(updater().updateUI);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
truncateErrors = () => {
|
truncateErrors = () => {
|
||||||
if (confirmMsg(this.props.msg.pkg.get("op.confirm"))) {
|
if (confirmMsg(this.props.msg.pkg.get("op.confirm"))) {
|
||||||
ErrorLogger().truncate();
|
ErrorLogger().truncate();
|
||||||
|
@ -354,6 +367,38 @@ export class PaneSettings extends React.Component<Props, State, {}> {
|
||||||
</div>
|
</div>
|
||||||
</Container>
|
</Container>
|
||||||
|
|
||||||
|
<Container>
|
||||||
|
<Flexbox
|
||||||
|
children={List([
|
||||||
|
<h5 className="title-m">
|
||||||
|
{this.props.msg.pkg.get("theme")}
|
||||||
|
</h5>,
|
||||||
|
])}
|
||||||
|
childrenStyles={List([{}, { justifyContent: "flex-end" }])}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="hr"></div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
this.setTheme("light");
|
||||||
|
}}
|
||||||
|
className="button-default inline-block margin-r-m"
|
||||||
|
>
|
||||||
|
{this.props.msg.pkg.get("theme.light")}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
this.setTheme("dark");
|
||||||
|
}}
|
||||||
|
className="button-default inline-block margin-r-m"
|
||||||
|
>
|
||||||
|
{this.props.msg.pkg.get("theme.dark")}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</Container>
|
||||||
|
|
||||||
{/* disabled */}
|
{/* disabled */}
|
||||||
{/* <Container>
|
{/* <Container>
|
||||||
<Flexbox
|
<Flexbox
|
||||||
|
|
|
@ -52,8 +52,10 @@ export class RootFrame extends React.Component<Props, State, {}> {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const bgStyle = this.makeBgStyle();
|
const bgStyle = this.makeBgStyle();
|
||||||
const themeDark = "theme-dark";
|
const theme =
|
||||||
const theme = themeDark;
|
this.props.login.preferences.theme === "light"
|
||||||
|
? "theme-default"
|
||||||
|
: "theme-dark";
|
||||||
const fontSizeClass = "font-m";
|
const fontSizeClass = "font-m";
|
||||||
|
|
||||||
const displaying = this.props.ui.control.controls.get(controlName);
|
const displaying = this.props.ui.control.controls.get(controlName);
|
||||||
|
|
|
@ -622,6 +622,7 @@ export class Updater {
|
||||||
cssURL: "",
|
cssURL: "",
|
||||||
lanPackURL: "",
|
lanPackURL: "",
|
||||||
lan: "en_US",
|
lan: "en_US",
|
||||||
|
theme: "light",
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -781,6 +782,10 @@ export class Updater {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
setTheme = (theme: string) => {
|
||||||
|
this.props.login.preferences.theme = theme;
|
||||||
|
};
|
||||||
|
|
||||||
setControlOption = (controlName: string, option: string): boolean => {
|
setControlOption = (controlName: string, option: string): boolean => {
|
||||||
const controlExists = this.props.ui.control.controls.has(controlName);
|
const controlExists = this.props.ui.control.controls.has(controlName);
|
||||||
const optionsExists = this.props.ui.control.options.has(controlName);
|
const optionsExists = this.props.ui.control.options.has(controlName);
|
||||||
|
|
|
@ -138,7 +138,10 @@ export const msgs: Map<string, string> = Map({
|
||||||
"endpoints.home": "Home",
|
"endpoints.home": "Home",
|
||||||
"state.stopped": "Stopped",
|
"state.stopped": "Stopped",
|
||||||
"state.error": "Error",
|
"state.error": "Error",
|
||||||
"usedSpace": "Used Space",
|
usedSpace: "Used Space",
|
||||||
"resetUsedSpace": "Reset Used Space",
|
resetUsedSpace: "Reset Used Space",
|
||||||
"confirm.resetUsedSpace": "The operation may take some time, do you confirm?"
|
"confirm.resetUsedSpace": "The operation may take some time, do you confirm?",
|
||||||
|
theme: "Theme",
|
||||||
|
"theme.light": "Light",
|
||||||
|
"theme.dark": "Dark",
|
||||||
});
|
});
|
||||||
|
|
|
@ -130,12 +130,15 @@ export const msgs: Map<string, string> = Map({
|
||||||
"op.cancel": "取消",
|
"op.cancel": "取消",
|
||||||
"term.time": "时间",
|
"term.time": "时间",
|
||||||
"breadcrumb.loc": "位置",
|
"breadcrumb.loc": "位置",
|
||||||
"endpoints": "端点",
|
endpoints: "端点",
|
||||||
"endpoints.root": "根",
|
"endpoints.root": "根",
|
||||||
"endpoints.home": "家",
|
"endpoints.home": "家",
|
||||||
"state.stopped": "已停止",
|
"state.stopped": "已停止",
|
||||||
"state.error": "错误",
|
"state.error": "错误",
|
||||||
"usedSpace": "已用空间",
|
usedSpace: "已用空间",
|
||||||
"resetUsedSpace": "重置已用空间",
|
resetUsedSpace: "重置已用空间",
|
||||||
"confirm.resetUsedSpace": "此操作可能会需要一些时间, 确认吗?"
|
"confirm.resetUsedSpace": "此操作可能会需要一些时间, 确认吗?",
|
||||||
|
theme: "主题",
|
||||||
|
"theme.light": "光白",
|
||||||
|
"theme.dark": "暗黑",
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue