diff --git a/apps/web/package.json b/apps/web/package.json index 4fd421db..8dccd4d6 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -21,6 +21,7 @@ "@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-popover": "^1.0.7", "@radix-ui/react-slot": "^1.0.2", + "cheerio": "^1.0.0-rc.12", "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", "cmdk": "latest", diff --git a/apps/web/src/actions/db.ts b/apps/web/src/actions/db.ts index c5481392..41789689 100644 --- a/apps/web/src/actions/db.ts +++ b/apps/web/src/actions/db.ts @@ -115,28 +115,6 @@ export async function getMemory(title: string) { ); } -export async function addMemory( - content: typeof storedContent.$inferInsert, - spaces: number[], -) { - - const user = await getUser(); - - if (!user) { - return null - } - content.user = user.id; - - const _content = ( - await db.insert(storedContent).values(content).returning() - )[0]; - await Promise.all( - spaces.map((spaceId) => - db.insert(contentToSpace).values({ contentId: _content.id, spaceId }), - ), - ); - return _content; -} export async function addSpace(name: string, memories: number[]) { @@ -215,3 +193,32 @@ export async function fetchFreeMemories( return range ? await query.limit(range.limit).offset(range.offset) : await query.all() } + +export async function addMemory(content: typeof storedContent.$inferInsert, spaces: number[]) { + + const user = await getUser() + + if (!user) { + return null + } + + const [addedMemory] = await db.insert(storedContent) + .values({ + user: user.id, + ...content + }) + .returning(); + + const addedToSpaces = spaces.length > 0 ? await db.insert(contentToSpace) + .values(spaces.map(s => ({ + contentId: addedMemory.id, + spaceId: s, + }))) + .returning() : []; + + return { + memory: addedMemory, + addedToSpaces + } + +} diff --git a/apps/web/src/assets/Note.tsx b/apps/web/src/assets/Note.tsx new file mode 100644 index 00000000..e69de29b diff --git a/apps/web/src/components/Sidebar/AddMemoryDialog.tsx b/apps/web/src/components/Sidebar/AddMemoryDialog.tsx index 1482774e..b9ab1d86 100644 --- a/apps/web/src/components/Sidebar/AddMemoryDialog.tsx +++ b/apps/web/src/components/Sidebar/AddMemoryDialog.tsx @@ -77,6 +77,9 @@ export function AddMemoryPage() { } export function NoteAddPage({ closeDialog }: { closeDialog: () => void }) { + + const { addMemory } = useMemory() + const [selectedSpacesId, setSelectedSpacesId] = useState([]); const inputRef = useRef(null); @@ -116,6 +119,7 @@ export function NoteAddPage({ closeDialog }: { closeDialog: () => void }) { placeholder="Title of the note" data-modal-autofocus value={name} + disabled={loading} onChange={(e) => setName(e.target.value)} /> void }) { Cancel diff --git a/apps/web/src/components/Sidebar/MemoriesBar.tsx b/apps/web/src/components/Sidebar/MemoriesBar.tsx index 88262f4e..eb26827c 100644 --- a/apps/web/src/components/Sidebar/MemoriesBar.tsx +++ b/apps/web/src/components/Sidebar/MemoriesBar.tsx @@ -194,7 +194,8 @@ const SpaceExitVariant: Variant = { export function MemoryItem({ id, title, - image + image, + type }: StoredContent) { const name = title ? title.length > 10 ? title.slice(0, 10) + "..." : title : ''; @@ -209,11 +210,19 @@ export function MemoryItem({
- + {type === "page" ? ( + + ): type === "note" ? ( +
+ +
+ ) : ( + <> + )}
) diff --git a/apps/web/src/contexts/MemoryContext.tsx b/apps/web/src/contexts/MemoryContext.tsx index 08d166a6..44fc9799 100644 --- a/apps/web/src/contexts/MemoryContext.tsx +++ b/apps/web/src/contexts/MemoryContext.tsx @@ -16,16 +16,13 @@ export const MemoryContext = React.createContext<{ deleteSpace: (id: number) => Promise; freeMemories: StoredContent[]; addSpace: typeof addSpace; - addMemory: ( - memory: typeof storedContent.$inferInsert, - spaces?: number[], - ) => Promise; + addMemory: typeof addMemory; cachedMemories: ChachedSpaceContent[]; search: typeof searchMemoriesAndSpaces; }>({ spaces: [], freeMemories: [], - addMemory: async () => {}, + addMemory: (() => {}) as unknown as (typeof addMemory), addSpace: (async () => {}) as unknown as (typeof addSpace), deleteSpace: async () => {}, cachedMemories: [], @@ -57,12 +54,6 @@ export const MemoryProvider: React.FC< // const response = await fetch(`/api/memories?${query}`); // }, []); - const _addMemory = async ( - memory: typeof storedContent.$inferInsert, - spaces: number[] = [], - ) => { - const content = await addMemory(memory, spaces); - } const _addSpace: typeof addSpace = async (...params) => { const { space: addedSpace, addedMemories } = (await addSpace(...params))!; @@ -80,6 +71,23 @@ export const MemoryProvider: React.FC< } } + const _addMemory: typeof addMemory = async (...params) => { + const { memory: addedMemory, addedToSpaces } = (await addMemory(...params))!; + + addedToSpaces.length > 0 ? setCachedMemories(prev => [ + ...prev, + ...addedToSpaces.map(s => ({ + ...addedMemory, + space: s.spaceId + })) + ]) : setFreeMemories(prev => [...prev, addedMemory]) + + return { + memory: addedMemory, + addedToSpaces + } + } + return ( (.*?)<\/title>/); - const title = titleMatch ? titleMatch[1] : "Title not found"; + const title = $('title').text().trim() - // Extract meta description - const descriptionMatch = html.match( - //, - ); - const description = descriptionMatch - ? descriptionMatch[1] - : "Description not found"; + const description = $('meta[name=description]').attr('content') ?? '' - // Extract favicon - const faviconMatch = html.match( - //, - ); - const favicon = faviconMatch - ? faviconMatch[1] - : "https://supermemory.dhr.wtf/web.svg"; + const _favicon = $('link[rel=icon]').attr('href') ?? 'https://supermemory.dhr.wtf/web.svg'; + + let favicon = _favicon.trim().length > 0 ? _favicon.trim() : 'https://supermemory.dhr.wtf/web.svg' + if (favicon.startsWith("/")) { + favicon = baseUrl + favicon + } // Prepare the metadata object const metadata = {