-
-
Notifications
You must be signed in to change notification settings - Fork 315
fix: update appreciation data properly #839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,7 @@ import cloneDeep from 'lodash/cloneDeep'; | |||||
| import { getAnimateDuration } from '@/Core/Modules/animationFunctions'; | ||||||
| import { WebGAL } from '@/Core/WebGAL'; | ||||||
| import { DEFAULT_BG_OUT_DURATION } from '@/Core/constants'; | ||||||
| import localforage from 'localforage'; | ||||||
|
|
||||||
| /** | ||||||
| * 进行背景图片的切换 | ||||||
|
|
@@ -34,6 +35,8 @@ export const changeBg = (sentence: ISentence): IPerform => { | |||||
| const dispatch = webgalStore.dispatch; | ||||||
| if (unlockName !== '') { | ||||||
| dispatch(unlockCgInUserData({ name: unlockName, url, series })); | ||||||
| const userDataState = webgalStore.getState().userData; | ||||||
| localforage.setItem(WebGAL.gameKey, userDataState).then(() => {}); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这部分用于持久化用户数据的逻辑与 另外,
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,7 +69,7 @@ const userDataSlice = createSlice({ | |
| state.appreciationData.cg.forEach((e) => { | ||
| if (url === e.url) { | ||
| isExist = true; | ||
| e.url = url; | ||
| e.name = name; | ||
| e.series = series; | ||
| } | ||
| }); | ||
|
Comment on lines
69
to
75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 使用 建议重构此逻辑,使用 例如,可以这样重构整个 unlockCgInUserData: (state, action: PayloadAction<IAppreciationAsset>) => {
const { name, url, series } = action.payload;
const existingCg = state.appreciationData.cg.find((e) => e.url === url);
if (existingCg) {
existingCg.name = name;
existingCg.series = series;
} else {
state.appreciationData.cg.push(action.payload);
}
},由于这会改变函数整体结构,因此不提供可直接应用的修改建议,但强烈建议进行此重构。 |
||
|
|
@@ -84,7 +84,7 @@ const userDataSlice = createSlice({ | |
| state.appreciationData.bgm.forEach((e) => { | ||
| if (url === e.url) { | ||
| isExist = true; | ||
| e.url = url; | ||
| e.name = name; | ||
| e.series = series; | ||
| } | ||
| }); | ||
|
Comment on lines
84
to
90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 与 重构示例: const { name, url, series } = action.payload;
const existingBgm = state.appreciationData.bgm.find((e) => e.url === url);
if (existingBgm) {
existingBgm.name = name;
existingBgm.series = series;
} else {
state.appreciationData.bgm.push(action.payload);
} |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分用于持久化用户数据的逻辑与
packages/webgal/src/Core/gameScripts/changeBg/index.ts中的代码重复了。为了提高代码的可维护性,建议将此逻辑提取到一个共享的辅助函数中。另外,
localforage.setItem是一个异步操作,目前的代码.then(() => {})会忽略任何可能发生的错误。建议添加错误处理逻辑,以便在数据保存失败时能够捕获并记录错误,这对于调试非常有帮助。