diff options
| author | yxshv <[email protected]> | 2024-04-11 16:37:46 +0530 |
|---|---|---|
| committer | yxshv <[email protected]> | 2024-04-11 16:37:46 +0530 |
| commit | 539f50367d2964579dbb6aa62876fab973b17840 (patch) | |
| tree | a071ab8c30d2448207bc68c92a57d5663dd73724 /apps/web/src/contexts | |
| parent | merge pls (diff) | |
| parent | Merge branch 'main' of https://github.com/Dhravya/supermemory (diff) | |
| download | supermemory-539f50367d2964579dbb6aa62876fab973b17840.tar.xz supermemory-539f50367d2964579dbb6aa62876fab973b17840.zip | |
Merge branch 'main' of https://github.com/dhravya/supermemory
Diffstat (limited to 'apps/web/src/contexts')
| -rw-r--r-- | apps/web/src/contexts/MemoryContext.tsx | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/apps/web/src/contexts/MemoryContext.tsx b/apps/web/src/contexts/MemoryContext.tsx index eab1e4fe..68a22434 100644 --- a/apps/web/src/contexts/MemoryContext.tsx +++ b/apps/web/src/contexts/MemoryContext.tsx @@ -1,22 +1,37 @@ "use client"; import React, { useCallback } from "react"; import { CollectedSpaces } from "../../types/memory"; +import { StoredContent, storedContent } from "@/server/db/schema"; +import { useSession } from "next-auth/react"; +import { addMemory } from "@/actions/db"; // temperory (will change) export const MemoryContext = React.createContext<{ spaces: CollectedSpaces[]; deleteSpace: (id: number) => Promise<void>; + freeMemories: StoredContent[]; addSpace: (space: CollectedSpaces) => Promise<void>; + addMemory: ( + memory: typeof storedContent.$inferInsert, + spaces?: number[], + ) => Promise<void>; }>({ spaces: [], - addSpace: async (space) => {}, - deleteSpace: async (id) => {}, + freeMemories: [], + addMemory: async () => {}, + addSpace: async () => {}, + deleteSpace: async () => {}, }); export const MemoryProvider: React.FC< - { spaces: CollectedSpaces[] } & React.PropsWithChildren -> = ({ children, spaces: initalSpaces }) => { + { + spaces: CollectedSpaces[]; + freeMemories: StoredContent[]; + } & React.PropsWithChildren +> = ({ children, spaces: initalSpaces, freeMemories: initialFreeMemories }) => { const [spaces, setSpaces] = React.useState<CollectedSpaces[]>(initalSpaces); + const [freeMemories, setFreeMemories] = + React.useState<StoredContent[]>(initialFreeMemories); const addSpace = useCallback( async (space: CollectedSpaces) => { @@ -31,8 +46,31 @@ export const MemoryProvider: React.FC< [spaces], ); + // const fetchMemories = useCallback(async (query: string) => { + // const response = await fetch(`/api/memories?${query}`); + // }, []); + + const _addMemory = useCallback( + async ( + memory: typeof storedContent.$inferInsert, + spaces: number[] = [], + ) => { + const content = await addMemory(memory, spaces); + console.log(content); + }, + [freeMemories, spaces], + ); + return ( - <MemoryContext.Provider value={{ spaces, addSpace, deleteSpace }}> + <MemoryContext.Provider + value={{ + spaces, + addSpace, + deleteSpace, + freeMemories, + addMemory: _addMemory, + }} + > {children} </MemoryContext.Provider> ); |