Commit 5bc1cc39 authored by hewenhao's avatar hewenhao

feat: 优化滚动

parent df42b9cb
......@@ -59,15 +59,19 @@ const MainPage = () => {
const tabbar = getTabBar<TabbarRef>(page)
tabbar?.setSelected(0)
fetchStage().then((list) => {
fetchStage().then(([list, preList]) => {
setTimeout(() => {
nextTick(() => {
if (!list.find(c => c.status === StageStatus.CURRENT)) {
const currentItem = list.find(c => c.status === StageStatus.CURRENT)
if (!currentItem) {
updateReady(true)
} else {
scrollToCurrent(() => {
updateReady(true)
})
const lastItem = preList.find(c => c.status === StageStatus.CURRENT)
if (currentItem?.id !== lastItem?.id) {
scrollToCurrent(() => {
updateReady(true)
})
}
setTimeout(() => {
updateReady(true)
}, 300)
......
......@@ -20,7 +20,7 @@ export interface MainModel {
player: InnerAudioContext;
updateReady: Action<MainModel, boolean>;
updateStageList: Action<MainModel, Stage[]>;
fetchStage: Thunk<MainModel, void, void, AppStoreModel, Promise<Stage[]>>;
fetchStage: Thunk<MainModel, void, void, AppStoreModel, Promise<[Stage[], Stage[]]>>;
}
const mainModel: MainModel = {
......@@ -33,7 +33,8 @@ const mainModel: MainModel = {
updateStageList: action((state, stageList) => {
state.stageList = stageList
}),
fetchStage: thunk(async (actions, _) => {
fetchStage: thunk(async (actions, _, helpers) => {
const { stageList: preStageList } = helpers.getState()
let ret: Stage[] = []
try {
const { data: stageList } = await getStageList()
......@@ -42,7 +43,7 @@ const mainModel: MainModel = {
ret = []
}
actions.updateStageList(ret)
return ret
return [ret, preStageList] as [Stage[], Stage[]]
}),
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment