feat: 新增体重记录功能,优化用户资料更新及图片组件缓存
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { api, loadPersistedToken, setAuthToken, STORAGE_KEYS } from '@/services/api';
|
||||
import { updateUser, UpdateUserDto } from '@/services/users';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import { createAsyncThunk, createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
|
||||
@@ -11,6 +12,8 @@ export type UserProfile = {
|
||||
birthDate?: string;
|
||||
weight?: string;
|
||||
height?: string;
|
||||
initialWeight?: string; // 初始体重
|
||||
targetWeight?: string; // 目标体重
|
||||
avatar?: string | null;
|
||||
dailyStepsGoal?: number; // 每日步数目标(用于 Explore 页等)
|
||||
dailyCaloriesGoal?: number; // 每日卡路里消耗目标
|
||||
@@ -194,6 +197,20 @@ export const fetchActivityHistory = createAsyncThunk('user/fetchActivityHistory'
|
||||
}
|
||||
});
|
||||
|
||||
// 更新用户资料(包括体重)
|
||||
export const updateUserProfile = createAsyncThunk(
|
||||
'user/updateProfile',
|
||||
async (updateDto: UpdateUserDto, { rejectWithValue }) => {
|
||||
try {
|
||||
const data = await updateUser(updateDto);
|
||||
console.log('updateUserProfile', data);
|
||||
return data;
|
||||
} catch (err: any) {
|
||||
return rejectWithValue(err?.message ?? '更新用户资料失败');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const userSlice = createSlice({
|
||||
name: 'user',
|
||||
initialState,
|
||||
@@ -263,6 +280,12 @@ const userSlice = createSlice({
|
||||
})
|
||||
.addCase(fetchActivityHistory.rejected, (state, action) => {
|
||||
state.error = (action.payload as string) ?? '获取用户活动历史记录失败';
|
||||
})
|
||||
.addCase(updateUserProfile.fulfilled, (state, action) => {
|
||||
state.profile = { ...state.profile, ...action.payload };
|
||||
})
|
||||
.addCase(updateUserProfile.rejected, (state, action) => {
|
||||
state.error = (action.payload as string) ?? '更新用户资料失败';
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user