Files
digital-pilates/store/index.ts
richarjiang 807e185761 feat: 更新应用版本和主题设置
- 将应用版本更新至 1.0.3,修改相关配置文件
- 强制全局使用浅色主题,确保一致的用户体验
- 在训练计划功能中新增激活计划的 API 接口,支持用户激活训练计划
- 优化打卡功能,支持自动同步打卡记录至服务器
- 更新样式以适应新功能的展示和交互
2025-08-14 22:23:45 +08:00

50 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { configureStore, createListenerMiddleware } from '@reduxjs/toolkit';
import challengeReducer from './challengeSlice';
import checkinReducer, { addExercise, autoSyncCheckin, removeExercise, replaceExercises, setNote, toggleExerciseCompleted } from './checkinSlice';
import trainingPlanReducer from './trainingPlanSlice';
import userReducer from './userSlice';
// 创建监听器中间件来处理自动同步
const listenerMiddleware = createListenerMiddleware();
// 监听所有数据变动的 actions触发自动同步
const syncActions = [addExercise, removeExercise, replaceExercises, toggleExerciseCompleted, setNote];
syncActions.forEach(action => {
listenerMiddleware.startListening({
actionCreator: action,
effect: async (action, listenerApi) => {
const state = listenerApi.getState() as any;
const date = action.payload?.date;
if (!date) return;
// 延迟一下,避免在同一事件循环中重复触发
await new Promise(resolve => setTimeout(resolve, 100));
// 检查是否还有待同步的日期
const currentState = listenerApi.getState() as any;
const pendingSyncDates = currentState?.checkin?.pendingSyncDates || [];
if (pendingSyncDates.includes(date)) {
listenerApi.dispatch(autoSyncCheckin({ date }));
}
},
});
});
export const store = configureStore({
reducer: {
user: userReducer,
challenge: challengeReducer,
checkin: checkinReducer,
trainingPlan: trainingPlanReducer,
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware().prepend(listenerMiddleware.middleware),
});
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;