Add OpenMemory (#2676)
Co-authored-by: Saket Aryan <94069182+whysosaket@users.noreply.github.com> Co-authored-by: Saket Aryan <saketaryan2002@gmail.com>
This commit is contained in:
63
openmemory/ui/store/profileSlice.ts
Normal file
63
openmemory/ui/store/profileSlice.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
|
||||
interface ProfileState {
|
||||
userId: string;
|
||||
totalMemories: number;
|
||||
totalApps: number;
|
||||
status: 'idle' | 'loading' | 'succeeded' | 'failed';
|
||||
error: string | null;
|
||||
apps: any[];
|
||||
}
|
||||
|
||||
const initialState: ProfileState = {
|
||||
userId: process.env.NEXT_PUBLIC_USER_ID || 'deshraj',
|
||||
totalMemories: 0,
|
||||
totalApps: 0,
|
||||
status: 'idle',
|
||||
error: null,
|
||||
apps: [],
|
||||
};
|
||||
|
||||
const profileSlice = createSlice({
|
||||
name: 'profile',
|
||||
initialState,
|
||||
reducers: {
|
||||
setUserId: (state, action: PayloadAction<string>) => {
|
||||
state.userId = action.payload;
|
||||
},
|
||||
setProfileLoading: (state) => {
|
||||
state.status = 'loading';
|
||||
state.error = null;
|
||||
},
|
||||
setProfileError: (state, action: PayloadAction<string>) => {
|
||||
state.status = 'failed';
|
||||
state.error = action.payload;
|
||||
},
|
||||
resetProfileState: (state) => {
|
||||
state.status = 'idle';
|
||||
state.error = null;
|
||||
state.userId = process.env.NEXT_PUBLIC_USER_ID || 'deshraj';
|
||||
},
|
||||
setTotalMemories: (state, action: PayloadAction<number>) => {
|
||||
state.totalMemories = action.payload;
|
||||
},
|
||||
setTotalApps: (state, action: PayloadAction<number>) => {
|
||||
state.totalApps = action.payload;
|
||||
},
|
||||
setApps: (state, action: PayloadAction<any[]>) => {
|
||||
state.apps = action.payload;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const {
|
||||
setUserId,
|
||||
setProfileLoading,
|
||||
setProfileError,
|
||||
resetProfileState,
|
||||
setTotalMemories,
|
||||
setTotalApps,
|
||||
setApps
|
||||
} = profileSlice.actions;
|
||||
|
||||
export default profileSlice.reducer;
|
||||
Reference in New Issue
Block a user