repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import { createSlice, PayloadAction } from '@reduxjs/toolkit'; |
| #2 | import { Memory } from '@/components/types'; |
| #3 | import { SimpleMemory } from '@/hooks/useMemoriesApi'; |
| #4 | |
| #5 | interface AccessLogEntry { |
| #6 | id: string; |
| #7 | app_name: string; |
| #8 | accessed_at: string; |
| #9 | } |
| #10 | |
| #11 | // Define the shape of the memories state |
| #12 | interface MemoriesState { |
| #13 | memories: Memory[]; |
| #14 | selectedMemory: SimpleMemory | null; |
| #15 | accessLogs: AccessLogEntry[]; |
| #16 | relatedMemories: Memory[]; |
| #17 | status: 'idle' | 'loading' | 'succeeded' | 'failed'; |
| #18 | error: string | null; |
| #19 | selectedMemoryIds: string[]; |
| #20 | } |
| #21 | |
| #22 | const initialState: MemoriesState = { |
| #23 | memories: [], |
| #24 | selectedMemory: null, |
| #25 | accessLogs: [], |
| #26 | relatedMemories: [], |
| #27 | status: 'idle', |
| #28 | error: null, |
| #29 | selectedMemoryIds: [], |
| #30 | }; |
| #31 | |
| #32 | const memoriesSlice = createSlice({ |
| #33 | name: 'memories', |
| #34 | initialState, |
| #35 | reducers: { |
| #36 | setSelectedMemory: (state, action: PayloadAction<SimpleMemory | null>) => { |
| #37 | state.selectedMemory = action.payload; |
| #38 | }, |
| #39 | setAccessLogs: (state, action: PayloadAction<AccessLogEntry[]>) => { |
| #40 | state.accessLogs = action.payload; |
| #41 | }, |
| #42 | setMemoriesLoading: (state) => { |
| #43 | state.status = 'loading'; |
| #44 | state.error = null; |
| #45 | state.memories = []; // Optionally clear old memories on new load |
| #46 | }, |
| #47 | setMemoriesSuccess: (state, action: PayloadAction<Memory[]>) => { |
| #48 | state.status = 'succeeded'; |
| #49 | state.memories = action.payload; |
| #50 | state.error = null; |
| #51 | }, |
| #52 | setMemoriesError: (state, action: PayloadAction<string>) => { |
| #53 | state.status = 'failed'; |
| #54 | state.error = action.payload; |
| #55 | }, |
| #56 | resetMemoriesState: (state) => { |
| #57 | state.status = 'idle'; |
| #58 | state.error = null; |
| #59 | state.memories = []; |
| #60 | state.selectedMemoryIds = []; |
| #61 | state.selectedMemory = null; |
| #62 | state.accessLogs = []; |
| #63 | state.relatedMemories = []; |
| #64 | }, |
| #65 | selectMemory: (state, action: PayloadAction<string>) => { |
| #66 | if (!state.selectedMemoryIds.includes(action.payload)) { |
| #67 | state.selectedMemoryIds.push(action.payload); |
| #68 | } |
| #69 | }, |
| #70 | deselectMemory: (state, action: PayloadAction<string>) => { |
| #71 | state.selectedMemoryIds = state.selectedMemoryIds.filter(id => id !== action.payload); |
| #72 | }, |
| #73 | selectAllMemories: (state) => { |
| #74 | state.selectedMemoryIds = state.memories.map(memory => memory.id); |
| #75 | }, |
| #76 | clearSelection: (state) => { |
| #77 | state.selectedMemoryIds = []; |
| #78 | }, |
| #79 | setRelatedMemories: (state, action: PayloadAction<Memory[]>) => { |
| #80 | state.relatedMemories = action.payload; |
| #81 | }, |
| #82 | }, |
| #83 | // extraReducers section is removed as API calls are handled by the hook |
| #84 | }); |
| #85 | |
| #86 | export const { |
| #87 | setMemoriesLoading, |
| #88 | setMemoriesSuccess, |
| #89 | setMemoriesError, |
| #90 | resetMemoriesState, |
| #91 | selectMemory, |
| #92 | deselectMemory, |
| #93 | selectAllMemories, |
| #94 | clearSelection, |
| #95 | setSelectedMemory, |
| #96 | setAccessLogs, |
| #97 | setRelatedMemories |
| #98 | } = memoriesSlice.actions; |
| #99 | |
| #100 | export default memoriesSlice.reducer; |