fix: 修复问题
- 修复刷课错误不会停止 - 添加课程刷新 - 添加课程列表、记录列表缓存 - 显示当前版本
This commit is contained in:
@@ -36,25 +36,32 @@ export type AccountItem = {
|
||||
courses: CourseType[];
|
||||
};
|
||||
|
||||
export type RecordCacheMap = Record<string, RecordItem[]>;
|
||||
|
||||
type AccountState = {
|
||||
accounts: AccountItem[];
|
||||
selectedAccountId: string;
|
||||
expandedAccountId: string;
|
||||
selectedCourseId: number | null;
|
||||
courseKind: CourseKind;
|
||||
recordType: RecordType;
|
||||
records: RecordItem[];
|
||||
recordCacheMap: RecordCacheMap;
|
||||
studyLogsMap: Record<string, string[]>;
|
||||
runningStudyMap: Record<string, boolean>;
|
||||
setSelectedAccountId: (accountId: string) => void;
|
||||
setExpandedAccountId: (accountId: string) => void;
|
||||
setSelectedCourseId: (courseId: number | null) => void;
|
||||
setCourseKind: (courseKind: CourseKind) => void;
|
||||
setRecordType: (recordType: RecordType) => void;
|
||||
setRecords: (records: RecordItem[]) => void;
|
||||
setRecordCache: (cacheKey: string, records: RecordItem[]) => void;
|
||||
setAccountRunningStudy: (accountId: string, value: boolean) => void;
|
||||
appendStudyLog: (accountId: string, message: string) => void;
|
||||
clearStudyLogs: (accountId: string) => void;
|
||||
clearAllStudyLogs: () => void;
|
||||
upsertAccount: (account: AccountItem) => void;
|
||||
setAccountCourses: (accountId: string, courses: CourseType[]) => void;
|
||||
removeAccount: (accountId: string) => void;
|
||||
};
|
||||
|
||||
@@ -65,8 +72,10 @@ export const accountStore = createStore<AccountState>()(
|
||||
selectedAccountId: "",
|
||||
expandedAccountId: "",
|
||||
selectedCourseId: null,
|
||||
courseKind: "run",
|
||||
recordType: "",
|
||||
records: [],
|
||||
recordCacheMap: {},
|
||||
studyLogsMap: {},
|
||||
runningStudyMap: {},
|
||||
setSelectedAccountId: (accountId) =>
|
||||
@@ -74,8 +83,16 @@ export const accountStore = createStore<AccountState>()(
|
||||
setExpandedAccountId: (accountId) =>
|
||||
set({ expandedAccountId: accountId }),
|
||||
setSelectedCourseId: (courseId) => set({ selectedCourseId: courseId }),
|
||||
setCourseKind: (courseKind) => set({ courseKind }),
|
||||
setRecordType: (recordType) => set({ recordType }),
|
||||
setRecords: (records) => set({ records }),
|
||||
setRecordCache: (cacheKey, records) =>
|
||||
set((state) => ({
|
||||
recordCacheMap: {
|
||||
...state.recordCacheMap,
|
||||
[cacheKey]: records,
|
||||
},
|
||||
})),
|
||||
setAccountRunningStudy: (accountId, value) =>
|
||||
set((state) => ({
|
||||
runningStudyMap: {
|
||||
@@ -113,6 +130,12 @@ export const accountStore = createStore<AccountState>()(
|
||||
selectedAccountId: account.id,
|
||||
expandedAccountId: account.id,
|
||||
})),
|
||||
setAccountCourses: (accountId, courses) =>
|
||||
set((state) => ({
|
||||
accounts: state.accounts.map((item) =>
|
||||
item.id === accountId ? { ...item, courses } : item,
|
||||
),
|
||||
})),
|
||||
removeAccount: (accountId) =>
|
||||
set((state) => {
|
||||
const nextAccounts = state.accounts.filter(
|
||||
@@ -133,6 +156,11 @@ export const accountStore = createStore<AccountState>()(
|
||||
? null
|
||||
: state.selectedCourseId,
|
||||
records: state.selectedAccountId === accountId ? [] : state.records,
|
||||
recordCacheMap: Object.fromEntries(
|
||||
Object.entries(state.recordCacheMap).filter(
|
||||
([key]) => !key.startsWith(`${accountId}::`),
|
||||
),
|
||||
),
|
||||
studyLogsMap: Object.fromEntries(
|
||||
Object.entries(state.studyLogsMap).filter(
|
||||
([key]) => key !== accountId,
|
||||
@@ -154,8 +182,10 @@ export const accountStore = createStore<AccountState>()(
|
||||
selectedAccountId: state.selectedAccountId,
|
||||
expandedAccountId: state.expandedAccountId,
|
||||
selectedCourseId: state.selectedCourseId,
|
||||
courseKind: state.courseKind,
|
||||
recordType: state.recordType,
|
||||
records: state.records,
|
||||
recordCacheMap: state.recordCacheMap,
|
||||
studyLogsMap: state.studyLogsMap,
|
||||
runningStudyMap: state.runningStudyMap,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user