feat: 缓存自定义主题

This commit is contained in:
streakingman 2022-10-02 21:50:43 +08:00
parent e7ae319ecf
commit c0de917641

View File

@ -225,26 +225,45 @@ const App: FC = () => {
useEffect(() => { useEffect(() => {
if (customThemeIdFromPath) { if (customThemeIdFromPath) {
// 自定义主题 // 自定义主题
Bmob.Query('config') const storageTheme = localStorage.getItem(customThemeIdFromPath);
.get(customThemeIdFromPath) if (storageTheme) {
.then((res) => { // 节省请求
// @ts-ignore try {
const { content } = res; const customTheme = JSON.parse(storageTheme);
try { if (!customTheme.pure) {
const customTheme = JSON.parse(content); setPureMode(false);
if (!customTheme.pure) { setThemes([...themes, customTheme]);
setPureMode(false);
setThemes([...themes, customTheme]);
}
setCurTheme(customTheme);
} catch (e) {
console.log(e);
} }
}) setCurTheme(customTheme);
.catch((e) => { } catch (e) {
setCurTheme({ ...curTheme, title: CUSTOM_THEME_FAIL_TIP });
console.log(e); console.log(e);
}); }
} else {
Bmob.Query('config')
.get(customThemeIdFromPath)
.then((res) => {
// @ts-ignore
const { content } = res;
localStorage.setItem(customThemeIdFromPath, content);
try {
const customTheme = JSON.parse(content);
if (!customTheme.pure) {
setPureMode(false);
setThemes([...themes, customTheme]);
}
setCurTheme(customTheme);
} catch (e) {
console.log(e);
}
})
.catch((e) => {
setCurTheme({
...curTheme,
title: CUSTOM_THEME_FAIL_TIP,
});
console.log(e);
});
}
} else if (themeFromPath) { } else if (themeFromPath) {
// 内置主题 // 内置主题
setCurTheme( setCurTheme(