mirror of
https://ghproxy.com/https://github.com/StreakingMan/solvable-sheep-game
synced 2025-05-25 12:48:16 +08:00
feat: 缓存自定义主题
This commit is contained in:
parent
e7ae319ecf
commit
c0de917641
21
src/App.tsx
21
src/App.tsx
|
@ -225,11 +225,26 @@ const App: FC = () => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (customThemeIdFromPath) {
|
if (customThemeIdFromPath) {
|
||||||
// 自定义主题
|
// 自定义主题
|
||||||
|
const storageTheme = localStorage.getItem(customThemeIdFromPath);
|
||||||
|
if (storageTheme) {
|
||||||
|
// 节省请求
|
||||||
|
try {
|
||||||
|
const customTheme = JSON.parse(storageTheme);
|
||||||
|
if (!customTheme.pure) {
|
||||||
|
setPureMode(false);
|
||||||
|
setThemes([...themes, customTheme]);
|
||||||
|
}
|
||||||
|
setCurTheme(customTheme);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
Bmob.Query('config')
|
Bmob.Query('config')
|
||||||
.get(customThemeIdFromPath)
|
.get(customThemeIdFromPath)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const { content } = res;
|
const { content } = res;
|
||||||
|
localStorage.setItem(customThemeIdFromPath, content);
|
||||||
try {
|
try {
|
||||||
const customTheme = JSON.parse(content);
|
const customTheme = JSON.parse(content);
|
||||||
if (!customTheme.pure) {
|
if (!customTheme.pure) {
|
||||||
|
@ -242,9 +257,13 @@ const App: FC = () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
setCurTheme({ ...curTheme, title: CUSTOM_THEME_FAIL_TIP });
|
setCurTheme({
|
||||||
|
...curTheme,
|
||||||
|
title: CUSTOM_THEME_FAIL_TIP,
|
||||||
|
});
|
||||||
console.log(e);
|
console.log(e);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
} else if (themeFromPath) {
|
} else if (themeFromPath) {
|
||||||
// 内置主题
|
// 内置主题
|
||||||
setCurTheme(
|
setCurTheme(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user