From 94c71cb834bf901263f730f6a0f50e6164e022ae Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 19 Nov 2023 09:38:04 +0800 Subject: [PATCH] chore: fix loading status --- web/src/components/MemoList.tsx | 4 ++++ web/src/pages/Explore.tsx | 4 ++++ web/src/store/module/memo.ts | 5 ++++- web/src/store/reducer/memo.ts | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/web/src/components/MemoList.tsx b/web/src/components/MemoList.tsx index c4da1cb8..b8784cbe 100644 --- a/web/src/components/MemoList.tsx +++ b/web/src/components/MemoList.tsx @@ -82,6 +82,10 @@ const MemoList: React.FC = () => { } }, [filter]); + useEffect(() => { + memoStore.setLoadingStatus("incomplete"); + }, []); + useEffect(() => { if (!fetchMoreRef.current) return; diff --git a/web/src/pages/Explore.tsx b/web/src/pages/Explore.tsx index ce96eb09..f781c88d 100644 --- a/web/src/pages/Explore.tsx +++ b/web/src/pages/Explore.tsx @@ -52,6 +52,10 @@ const Explore = () => { .filter((m) => m.rowStatus === "NORMAL" && m.visibility !== "PRIVATE" && !m.parent) .sort((mi, mj) => mj.displayTs - mi.displayTs); + useEffect(() => { + memoStore.setLoadingStatus("incomplete"); + }, []); + useEffect(() => { if (!fetchMoreRef.current) return; diff --git a/web/src/store/module/memo.ts b/web/src/store/module/memo.ts index 19fa77fb..11e91498 100644 --- a/web/src/store/module/memo.ts +++ b/web/src/store/module/memo.ts @@ -2,7 +2,7 @@ import { omit } from "lodash-es"; import * as api from "@/helpers/api"; import { DEFAULT_MEMO_LIMIT } from "@/helpers/consts"; import store, { useAppSelector } from "../"; -import { updateLoadingStatus, createMemo, deleteMemo, patchMemo, upsertMemos } from "../reducer/memo"; +import { updateLoadingStatus, createMemo, deleteMemo, patchMemo, upsertMemos, LoadingStatus } from "../reducer/memo"; import { useMemoCacheStore } from "../v1"; export const convertResponseModelMemo = (memo: Memo): Memo => { @@ -82,6 +82,9 @@ export const useMemoStore = () => { }); return archivedMemos; }, + setLoadingStatus: (status: LoadingStatus) => { + store.dispatch(updateLoadingStatus(status)); + }, fetchMemoById, getMemoById: async (memoId: MemoId) => { for (const m of state.memos) { diff --git a/web/src/store/reducer/memo.ts b/web/src/store/reducer/memo.ts index 2c9ef6a9..31ac21f2 100644 --- a/web/src/store/reducer/memo.ts +++ b/web/src/store/reducer/memo.ts @@ -1,7 +1,7 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit"; import { uniqBy } from "lodash-es"; -type LoadingStatus = "incomplete" | "fetching" | "complete"; +export type LoadingStatus = "incomplete" | "fetching" | "complete"; interface State { loadingStatus: LoadingStatus;