diff options
| author | Yash <[email protected]> | 2024-04-05 08:47:06 +0000 |
|---|---|---|
| committer | Yash <[email protected]> | 2024-04-05 08:47:06 +0000 |
| commit | 3340c291f695ca6f7420030c04df564294ed2a2c (patch) | |
| tree | 85ee7583690ecff237fdf01fcfa42338281861a6 /apps/web/src/contexts | |
| parent | add context and fix sidebar (diff) | |
| download | supermemory-3340c291f695ca6f7420030c04df564294ed2a2c.tar.xz supermemory-3340c291f695ca6f7420030c04df564294ed2a2c.zip | |
`addSpace` function to the context
Diffstat (limited to 'apps/web/src/contexts')
| -rw-r--r-- | apps/web/src/contexts/MemoryContext.tsx | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/apps/web/src/contexts/MemoryContext.tsx b/apps/web/src/contexts/MemoryContext.tsx index 5be39ffc..6d84f95e 100644 --- a/apps/web/src/contexts/MemoryContext.tsx +++ b/apps/web/src/contexts/MemoryContext.tsx @@ -1,19 +1,30 @@ "use client"; -import React from "react"; +import React, { useCallback } from "react"; import { CollectedSpaces } from "../../types/memory"; // temperory (will change) export const MemoryContext = React.createContext<{ spaces: CollectedSpaces[]; + addSpace: (space: CollectedSpaces) => Promise<void>; }>({ spaces: [], + addSpace: async (space) => {}, }); export const MemoryProvider: React.FC< { spaces: CollectedSpaces[] } & React.PropsWithChildren -> = ({ children, spaces }) => { +> = ({ children, spaces: initalSpaces }) => { + const [spaces, setSpaces] = React.useState<CollectedSpaces[]>(initalSpaces); + + const addSpace = useCallback( + async (space: CollectedSpaces) => { + setSpaces((prev) => [...prev, space]); + }, + [spaces], + ); + return ( - <MemoryContext.Provider value={{ spaces }}> + <MemoryContext.Provider value={{ spaces, addSpace }}> {children} </MemoryContext.Provider> ); |