From e6fc9c42278d979b155fd71b1f8f13e72c990208 Mon Sep 17 00:00:00 2001 From: Yash Date: Thu, 11 Apr 2024 01:34:49 +0000 Subject: ok --- apps/web/src/components/Sidebar.tsx | 145 ----------------- .../web/src/components/Sidebar/AddMemoryDialog.tsx | 39 +++++ apps/web/src/components/Sidebar/MemoriesBar.tsx | 174 ++++++++++----------- 3 files changed, 120 insertions(+), 238 deletions(-) delete mode 100644 apps/web/src/components/Sidebar.tsx create mode 100644 apps/web/src/components/Sidebar/AddMemoryDialog.tsx (limited to 'apps/web/src') diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx deleted file mode 100644 index 66ca1652..00000000 --- a/apps/web/src/components/Sidebar.tsx +++ /dev/null @@ -1,145 +0,0 @@ -'use client'; -import { StoredContent } from '@/server/db/schema'; -import { - Plus, - MoreHorizontal, - ArrowUpRight, - Edit3, - Trash2, -} from 'lucide-react'; -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuTrigger, -} from './ui/dropdown-menu'; - -import { useState, useEffect, useRef } from 'react'; - -export default function Sidebar() { - const websites: StoredContent[] = [ - { - id: 1, - content: '', - title: 'Visual Studio Code', - url: 'https://code.visualstudio.com', - description: '', - image: 'https://code.visualstudio.com/favicon.ico', - baseUrl: 'https://code.visualstudio.com', - savedAt: new Date() - }, - { - id: 1, - content: '', - title: "yxshv/vscode: An unofficial remake of vscode's landing page", - url: 'https://github.com/yxshv/vscode', - description: '', - image: 'https://github.com/favicon.ico', - baseUrl: 'https://github.com', - savedAt: new Date() - }, - ]; - - return ( - - ); -} - -export const ListItem: React.FC<{ item: StoredContent }> = ({ item }) => { - const [isEditing, setIsEditing] = useState(false); - const editInputRef = useRef(null); - - useEffect(() => { - if (isEditing) { - setTimeout(() => { - editInputRef.current?.focus(); - }, 500); - } - }, [isEditing]); - - return ( -
- isEditing && e.preventDefault()} - className="flex w-[90%] items-center gap-2 focus:outline-none" - > - {isEditing ? ( - - ) : ( - <> - {item.title - - - )} - {isEditing ? ( - setIsEditing(false)} - onKeyDown={(e) => e.key === 'Escape' && setIsEditing(false)} - /> - ) : ( - - {item.title ?? 'Untitled website'} - - )} - - - - - - - window.open(item.url)}> - - Open - - { - setIsEditing(true); - }} - > - - Edit - - - - Delete - - - -
- ); -}; diff --git a/apps/web/src/components/Sidebar/AddMemoryDialog.tsx b/apps/web/src/components/Sidebar/AddMemoryDialog.tsx new file mode 100644 index 00000000..1bd4b688 --- /dev/null +++ b/apps/web/src/components/Sidebar/AddMemoryDialog.tsx @@ -0,0 +1,39 @@ +import { useEffect, useRef } from "react"; +import { + DialogClose, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "../ui/dialog"; +import { Input } from "../ui/input"; +import { Label } from "../ui/label"; + +export default function AddMemoryPage() { + return ( + <> + + Add a web page to memory + + This will take you the web page you are trying to add to memory, where + the extension will save the page to memory + + + + + + + Add + + + Cancel + + + + ); +} diff --git a/apps/web/src/components/Sidebar/MemoriesBar.tsx b/apps/web/src/components/Sidebar/MemoriesBar.tsx index d7d8b5b5..779dea25 100644 --- a/apps/web/src/components/Sidebar/MemoriesBar.tsx +++ b/apps/web/src/components/Sidebar/MemoriesBar.tsx @@ -1,10 +1,13 @@ +import { Editor } from "novel"; import { useAutoAnimate } from "@formkit/auto-animate/react"; import { MemoryWithImage, MemoryWithImages3, MemoryWithImages2, } from "@/assets/MemoryWithImages"; -import { type CollectedSpaces } from "../../../types/memory"; +import { type CollectedSpaces } + +from "../../../types/memory"; import { Input, InputWithIcon } from "../ui/input"; import { ArrowUpRight, @@ -22,7 +25,7 @@ import { DropdownMenuItem, DropdownMenuTrigger, } from "../ui/dropdown-menu"; -import { useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { Variant, useAnimate, motion } from "framer-motion"; import { useMemory } from "@/contexts/MemoryContext"; import { SpaceIcon } from "@/assets/Memories"; @@ -38,6 +41,8 @@ import { import { Label } from "../ui/label"; import useViewport from "@/hooks/useViewport"; import useTouchHold from "@/hooks/useTouchHold"; +import { DialogTrigger } from "@radix-ui/react-dialog"; +import AddMemoryPage from "./AddMemoryDialog"; export function MemoriesBar() { const [parent, enableAnimations] = useAutoAnimate(); @@ -59,38 +64,43 @@ export function MemoriesBar() { />
- - - - - - { - setIsDropdownOpen(false); - setAddMemoryState("page"); - }} - > - - Page to Memory - - - - Note - - - - Space - - - + + + + + + e.preventDefault()}> + + { + setAddMemoryState("page"); + }} + > + + Page to Memory + + + + { + setAddMemoryState("note"); + }} + > + + Note + + + + + Space + + + +
-
void; + type: "page" | "note" | "space" | null; + children?: React.ReactNode | React.ReactNode[]; + isOpen: boolean; }) { return ( - <> - onStateChange(open ? "page" : null)} + + {children} + { + e.preventDefault(); + ( + document.querySelector("[data-autofocus]") as + | HTMLInputElement + | undefined + )?.focus(); + }} > - - - Add a web page to memory - - This will take you the web page you are trying to add to memory, - where the extension will save the page to memory - - - - - - - Add - - - Cancel - - - - - - - - Add a web page to memory - - This will take you the web page you are trying to add to memory, - where the extension will save the page to memory - - - - - - - Add - - - Cancel - - - - - + {type === "page" && } + {type === "note" && ( + <> + + + + + Add + + + Cancel + + + + )} + + ); } -- cgit v1.2.3 From 9220d5f2431ed4361adc4f69e7d77a44d5794fff Mon Sep 17 00:00:00 2001 From: Dhravya Date: Wed, 10 Apr 2024 18:57:45 -0700 Subject: some branding attempts --- apps/web/src/app/globals.css | 2 +- apps/web/src/app/layout.tsx | 5 +++-- apps/web/src/components/Main.tsx | 8 +++++--- apps/web/src/components/Sidebar.tsx | 2 +- apps/web/src/components/Sidebar/index.tsx | 27 ++++++++++++++++++++++++--- apps/web/src/components/WordMark.tsx | 12 ++++++++++++ 6 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 apps/web/src/components/WordMark.tsx (limited to 'apps/web/src') diff --git a/apps/web/src/app/globals.css b/apps/web/src/app/globals.css index f5d09a67..69b46387 100644 --- a/apps/web/src/app/globals.css +++ b/apps/web/src/app/globals.css @@ -20,7 +20,7 @@ } body { - @apply bg-rgray-2 text-rgray-11 max-h-screen overflow-y-hidden; + @apply text-rgray-11 max-h-screen overflow-y-hidden bg-white; /* color: rgb(var(--foreground-rgb)); background: linear-gradient( to bottom, diff --git a/apps/web/src/app/layout.tsx b/apps/web/src/app/layout.tsx index 1b204dec..42485461 100644 --- a/apps/web/src/app/layout.tsx +++ b/apps/web/src/app/layout.tsx @@ -1,8 +1,9 @@ import type { Metadata } from "next"; -import { Roboto } from "next/font/google"; +import { Roboto, Inter } from "next/font/google"; import "./globals.css"; const roboto = Roboto({ weight: ["300", "400", "500"], subsets: ["latin"] }); +const inter = Inter({ weight: ["300", "400", "500"], subsets: ["latin"] }); export const metadata: Metadata = { title: "Create Next App", @@ -16,7 +17,7 @@ export default function RootLayout({ }>) { return ( - +
{children}
diff --git a/apps/web/src/components/Main.tsx b/apps/web/src/components/Main.tsx index 09703c2f..eec0c65b 100644 --- a/apps/web/src/components/Main.tsx +++ b/apps/web/src/components/Main.tsx @@ -11,6 +11,7 @@ import { ChatHistory } from "../../types/memory"; import { ChatAnswer, ChatMessage, ChatQuestion } from "./ChatMessage"; import { useRouter, useSearchParams } from "next/navigation"; import { useMemory } from "@/contexts/MemoryContext"; +import WordMark from "./WordMark"; function supportsDVH() { try { @@ -293,8 +294,9 @@ export default function Main({ sidebarOpen }: { sidebarOpen: boolean }) { hide ? "" : "main-hidden", )} > -

- Ask your Second brain +

+ Never forget anything. You are now{" "} + Smorter.

= ({ item }) => { ) : ( <> {item.title diff --git a/apps/web/src/components/Sidebar/index.tsx b/apps/web/src/components/Sidebar/index.tsx index 965455e6..9e6bdcce 100644 --- a/apps/web/src/components/Sidebar/index.tsx +++ b/apps/web/src/components/Sidebar/index.tsx @@ -8,11 +8,14 @@ import { Bin } from "@/assets/Bin"; import { Avatar, AvatarFallback, AvatarImage } from "@radix-ui/react-avatar"; import { useSession } from "next-auth/react"; import MessagePoster from "@/app/MessagePoster"; +import Image from "next/image"; +import WordMark from "../WordMark"; export type MenuItem = { icon: React.ReactNode | React.ReactNode[]; label: string; content?: React.ReactNode; + labelDisplay?: React.ReactNode; }; export default function Sidebar({ @@ -73,7 +76,25 @@ export default function Sidebar({ return ( <>
-
+
+ + ), + labelDisplay: , + }} + selectedItem={selectedItem} + setSelectedItem={setSelectedItem} + /> + {icon} - {label} + {labelDisplay ?? label} ); diff --git a/apps/web/src/components/WordMark.tsx b/apps/web/src/components/WordMark.tsx new file mode 100644 index 00000000..eb55647c --- /dev/null +++ b/apps/web/src/components/WordMark.tsx @@ -0,0 +1,12 @@ +import { cn } from "@/lib/utils"; +import React from "react"; + +function WordMark({ className }: { className?: string }) { + return ( + + smort. + + ); +} + +export default WordMark; -- cgit v1.2.3 From 4a90aaabf3fd41754b990f50ef4cbfa03723b0a8 Mon Sep 17 00:00:00 2001 From: Yash Date: Thu, 11 Apr 2024 02:22:33 +0000 Subject: novel editor --- apps/web/src/app/globals.css | 55 +++++++++++++++++++++- .../web/src/components/Sidebar/AddMemoryDialog.tsx | 31 ++++++++++-- apps/web/src/components/Sidebar/MemoriesBar.tsx | 42 ++++++++--------- 3 files changed, 100 insertions(+), 28 deletions(-) (limited to 'apps/web/src') diff --git a/apps/web/src/app/globals.css b/apps/web/src/app/globals.css index f19a0b57..cedb03dc 100644 --- a/apps/web/src/app/globals.css +++ b/apps/web/src/app/globals.css @@ -57,14 +57,65 @@ body { padding-bottom: 15dvh; } -.chat-answer pre { +.chat-answer pre { @apply bg-rgray-3 rounded-md border border-rgray-5 p-3 text-sm my-5; } +.novel-editor pre { + @apply bg-rgray-3 rounded-md border border-rgray-5 p-4 text-sm text-rgray-11; +} + .chat-answer h1 { @apply text-rgray-11 text-xl font-medium my-5; } .chat-answer img { @apply rounded-md font-medium my-5; -} \ No newline at end of file +} + +.tippy-box { + @apply bg-rgray-3 text-rgray-11 border border-rgray-5 rounded-md py-0; +} + +.tippy-content #slash-command { + @apply text-rgray-11 bg-transparent border-none; +} + +#slash-command button { + @apply text-rgray-11 py-2; +} + +#slash-command button div:first-child { + @apply text-rgray-11 bg-rgray-4 border-rgray-5 ; +} + +#slash-command button.novel-bg-stone-100 { + @apply bg-rgray-1; +} + +.novel-editor [data-type=taskList] > li { + @apply my-0; +} + +.novel-editor input[type=checkbox] { + @apply accent-rgray-4 rounded-md; + + background: var(--gray-4) !important; + border: 1px solid var(--gray-10) !important; +} + +.novel-editor .is-editor-empty::before { + content: 'Press \'/\' for commands' !important; +} + +.novel-editor h1 { + @apply text-2xl; +} + +.novel-editor h2 { + @apply text-xl; +} + +.novel-editor h3 { + @apply text-lg; +} diff --git a/apps/web/src/components/Sidebar/AddMemoryDialog.tsx b/apps/web/src/components/Sidebar/AddMemoryDialog.tsx index 1bd4b688..5a1d92f0 100644 --- a/apps/web/src/components/Sidebar/AddMemoryDialog.tsx +++ b/apps/web/src/components/Sidebar/AddMemoryDialog.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef } from "react"; +import { Editor } from "novel"; import { DialogClose, DialogDescription, @@ -8,8 +8,9 @@ import { } from "../ui/dialog"; import { Input } from "../ui/input"; import { Label } from "../ui/label"; +import { useRef } from "react"; -export default function AddMemoryPage() { +export function AddMemoryPage() { return ( <> @@ -23,7 +24,7 @@ export default function AddMemoryPage() { @@ -37,3 +38,27 @@ export default function AddMemoryPage() { ); } + +export function NoteAddPage() { + return ( + <> + + + + + Add + + + Cancel + + + + ); +} diff --git a/apps/web/src/components/Sidebar/MemoriesBar.tsx b/apps/web/src/components/Sidebar/MemoriesBar.tsx index 779dea25..83984233 100644 --- a/apps/web/src/components/Sidebar/MemoriesBar.tsx +++ b/apps/web/src/components/Sidebar/MemoriesBar.tsx @@ -5,9 +5,7 @@ import { MemoryWithImages3, MemoryWithImages2, } from "@/assets/MemoryWithImages"; -import { type CollectedSpaces } - -from "../../../types/memory"; +import { type CollectedSpaces } from "../../../types/memory"; import { Input, InputWithIcon } from "../ui/input"; import { ArrowUpRight, @@ -42,7 +40,7 @@ import { Label } from "../ui/label"; import useViewport from "@/hooks/useViewport"; import useTouchHold from "@/hooks/useTouchHold"; import { DialogTrigger } from "@radix-ui/react-dialog"; -import AddMemoryPage from "./AddMemoryDialog"; +import { AddMemoryPage, NoteAddPage } from "./AddMemoryDialog"; export function MemoriesBar() { const [parent, enableAnimations] = useAutoAnimate(); @@ -319,32 +317,30 @@ export function AddMemoryModal({ { e.preventDefault(); + const novel = document.querySelector('[contenteditable="true"]') as + | HTMLDivElement + | undefined; + if (novel) { + novel.autofocus = false; + novel.onfocus = () => { + ( + document.querySelector("[data-modal-autofocus]") as + | HTMLInputElement + | undefined + )?.focus(); + novel.onfocus = null; + }; + } ( - document.querySelector("[data-autofocus]") as + document.querySelector("[data-modal-autofocus]") as | HTMLInputElement | undefined )?.focus(); }} + className="w-max max-w-[auto]" > {type === "page" && } - {type === "note" && ( - <> - - - - - Add - - - Cancel - - - - )} + {type === "note" && } ); -- cgit v1.2.3 From efe6c946cbf95d914cddbbbfa383a62455c3957a Mon Sep 17 00:00:00 2001 From: Dhravya Date: Wed, 10 Apr 2024 21:40:21 -0700 Subject: save user ID with url to ensure that same website can be saved by users --- apps/web/src/components/Main.tsx | 3 +-- apps/web/src/components/Sidebar/index.tsx | 26 ++++++++------------------ 2 files changed, 9 insertions(+), 20 deletions(-) (limited to 'apps/web/src') diff --git a/apps/web/src/components/Main.tsx b/apps/web/src/components/Main.tsx index eec0c65b..b34755f9 100644 --- a/apps/web/src/components/Main.tsx +++ b/apps/web/src/components/Main.tsx @@ -295,8 +295,7 @@ export default function Main({ sidebarOpen }: { sidebarOpen: boolean }) { )} >

- Never forget anything. You are now{" "} - Smorter. + Ask your second brain

- - ), - labelDisplay: , - }} - selectedItem={selectedItem} - setSelectedItem={setSelectedItem} + Smort logo +
+ -
- Date: Wed, 10 Apr 2024 22:02:32 -0700 Subject: changes in how we save vectors --- apps/web/src/components/Main.tsx | 4 +- apps/web/src/components/QueryAI.tsx | 139 ------------------------------------ apps/web/src/lib/utils.ts | 5 ++ 3 files changed, 7 insertions(+), 141 deletions(-) delete mode 100644 apps/web/src/components/QueryAI.tsx (limited to 'apps/web/src') diff --git a/apps/web/src/components/Main.tsx b/apps/web/src/components/Main.tsx index b34755f9..1ef89e2d 100644 --- a/apps/web/src/components/Main.tsx +++ b/apps/web/src/components/Main.tsx @@ -6,7 +6,7 @@ import { ArrowRight, ArrowUp } from "lucide-react"; import { MemoryDrawer } from "./MemoryDrawer"; import useViewport from "@/hooks/useViewport"; import { AnimatePresence, motion } from "framer-motion"; -import { cn, countLines } from "@/lib/utils"; +import { cn, countLines, getIdsFromSource } from "@/lib/utils"; import { ChatHistory } from "../../types/memory"; import { ChatAnswer, ChatMessage, ChatQuestion } from "./ChatMessage"; import { useRouter, useSearchParams } from "next/navigation"; @@ -221,7 +221,7 @@ export default function Main({ sidebarOpen }: { sidebarOpen: boolean }) { ...lastMessage, answer: { parts: lastMessage.answer.parts, - sources: sourcesInJson.ids ?? [], + sources: getIdsFromSource(sourcesInJson.ids) ?? [], }, }, ]; diff --git a/apps/web/src/components/QueryAI.tsx b/apps/web/src/components/QueryAI.tsx deleted file mode 100644 index 894b5d2d..00000000 --- a/apps/web/src/components/QueryAI.tsx +++ /dev/null @@ -1,139 +0,0 @@ -"use client"; - -import { Label } from "./ui/label"; -import React, { useEffect, useState } from "react"; -import { Input } from "./ui/input"; -import { Button } from "./ui/button"; -import SearchResults from "./SearchResults"; - -function QueryAI() { - const [searchResults, setSearchResults] = useState([]); - const [isAiLoading, setIsAiLoading] = useState(false); - - const [aiResponse, setAIResponse] = useState(""); - const [input, setInput] = useState(""); - const [toBeParsed, setToBeParsed] = useState(""); - - const handleStreamData = (newChunk: string) => { - // Append the new chunk to the existing data to be parsed - setToBeParsed((prev) => prev + newChunk); - }; - - useEffect(() => { - // Define a function to try parsing the accumulated data - const tryParseAccumulatedData = () => { - // Attempt to parse the "toBeParsed" state as JSON - try { - // Split the accumulated data by the known delimiter "\n\n" - const parts = toBeParsed.split("\n\n"); - let remainingData = ""; - - // Process each part to extract JSON objects - parts.forEach((part, index) => { - try { - const parsedPart = JSON.parse(part.replace("data: ", "")); // Try to parse the part as JSON - - // If the part is the last one and couldn't be parsed, keep it to accumulate more data - if (index === parts.length - 1 && !parsedPart) { - remainingData = part; - } else if (parsedPart && parsedPart.response) { - // If the part is parsable and has the "response" field, update the AI response state - setAIResponse((prev) => prev + parsedPart.response); - } - } catch (error) { - // If parsing fails and it's not the last part, it's a malformed JSON - if (index !== parts.length - 1) { - console.error("Malformed JSON part: ", part); - } else { - // If it's the last part, it may be incomplete, so keep it - remainingData = part; - } - } - }); - - // Update the toBeParsed state to only contain the unparsed remainder - if (remainingData !== toBeParsed) { - setToBeParsed(remainingData); - } - } catch (error) { - console.error("Error parsing accumulated data: ", error); - } - }; - - // Call the parsing function if there's data to be parsed - if (toBeParsed) { - tryParseAccumulatedData(); - } - }, [toBeParsed]); - - const getSearchResults = async (e: React.FormEvent) => { - e.preventDefault(); - setIsAiLoading(true); - - const sourcesResponse = await fetch( - `/api/query?sourcesOnly=true&q=${input}`, - ); - - const sourcesInJson = (await sourcesResponse.json()) as { - ids: string[]; - }; - - setSearchResults(sourcesInJson.ids); - - const response = await fetch(`/api/query?q=${input}`); - - if (response.status !== 200) { - setIsAiLoading(false); - return; - } - - if (response.body) { - let reader = response.body.getReader(); - let decoder = new TextDecoder("utf-8"); - let result = ""; - - // @ts-ignore - reader.read().then(function processText({ done, value }) { - if (done) { - // setSearchResults(JSON.parse(result.replace('data: ', ''))); - // setIsAiLoading(false); - return; - } - - handleStreamData(decoder.decode(value)); - - return reader.read().then(processText); - }); - } - }; - - return ( -
-
await getSearchResults(e)} className="mt-8"> - -
- setInput(e.target.value)} - placeholder="Search using AI... ✨" - id="searchInput" - /> - -
-
- - {searchResults && ( - - )} -
- ); -} - -export default QueryAI; diff --git a/apps/web/src/lib/utils.ts b/apps/web/src/lib/utils.ts index 5eca08cc..4f34e990 100644 --- a/apps/web/src/lib/utils.ts +++ b/apps/web/src/lib/utils.ts @@ -18,6 +18,11 @@ export function cleanUrl(url: string) { : url; } +export function getIdsFromSource(sourceIds: string[]) { + // This function converts an id from a form of `websiteURL-userID` to just the websiteURL + return sourceIds.map((id) => id.split("-").slice(0, -1).join("-")); +} + export function generateId() { return Math.random().toString(36).slice(2, 9); } -- cgit v1.2.3 From b425476cc495c561988a789eb9d94e3d947735be Mon Sep 17 00:00:00 2001 From: Yash Date: Thu, 11 Apr 2024 05:57:42 +0000 Subject: notess --- apps/web/src/app/globals.css | 6 ++- apps/web/src/components/Main.tsx | 36 ++++--------- .../web/src/components/Sidebar/AddMemoryDialog.tsx | 60 +++++++++++++++++++--- apps/web/src/components/Sidebar/MemoriesBar.tsx | 12 +++-- apps/web/src/components/Sidebar/index.tsx | 12 ----- 5 files changed, 75 insertions(+), 51 deletions(-) (limited to 'apps/web/src') diff --git a/apps/web/src/app/globals.css b/apps/web/src/app/globals.css index 23caee5b..b09627ba 100644 --- a/apps/web/src/app/globals.css +++ b/apps/web/src/app/globals.css @@ -104,7 +104,7 @@ body { border: 1px solid var(--gray-10) !important; } -.novel-editor .is-editor-empty::before { +.novel-editor .is-empty::before { content: 'Press \'/\' for commands' !important; } @@ -119,3 +119,7 @@ body { .novel-editor h3 { @apply text-lg; } + +.novel-editor .drag-handle { + @apply hidden; +} \ No newline at end of file diff --git a/apps/web/src/components/Main.tsx b/apps/web/src/components/Main.tsx index b34755f9..b71c5334 100644 --- a/apps/web/src/components/Main.tsx +++ b/apps/web/src/components/Main.tsx @@ -11,7 +11,8 @@ import { ChatHistory } from "../../types/memory"; import { ChatAnswer, ChatMessage, ChatQuestion } from "./ChatMessage"; import { useRouter, useSearchParams } from "next/navigation"; import { useMemory } from "@/contexts/MemoryContext"; -import WordMark from "./WordMark"; + +import Image from "next/image"; function supportsDVH() { try { @@ -21,30 +22,6 @@ function supportsDVH() { } } -const failResponse = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. In volutpat bibendum ligula, nec consectetur purus iaculis eu. Sed venenatis magna at lacus efficitur, vel faucibus sem lobortis. Sed sit amet imperdiet eros, nec vestibulum ante. Integer ut eros pulvinar, tempus augue a, blandit nisl. Nulla ut ligula molestie, tincidunt ligula vitae, rhoncus tellus. Vestibulum molestie, orci nec scelerisque finibus, mauris eros convallis urna, vitae vehicula metus nisi id urna. Phasellus non metus et lectus sollicitudin convallis a sit amet turpis. Donec id lacinia sapien. - -Donec eget eros diam. Ut enim nunc, placerat vitae augue vel, rutrum dapibus felis. Nulla et ultrices ex. In sed arcu eget lectus scelerisque semper. Nullam aliquam luctus ultrices. Morbi finibus nec dolor vitae mattis. Quisque ligula dui, ullamcorper sed blandit et, maximus vel quam. Nunc id eros id sapien tempor feugiat sit amet sed mi. Quisque feugiat hendrerit libero non cursus. Praesent convallis, diam eget ullamcorper bibendum, est tellus blandit velit, vel cursus diam turpis sed nisi. - -Cras dictum tortor ex, id ullamcorper nibh mollis quis. Fusce mollis, massa vel sodales consectetur, lorem mi vehicula erat, id tincidunt lorem libero at augue. Suspendisse vitae enim varius, molestie augue ut, lobortis ipsum. Nam lobortis leo eget velit auctor, ac consequat nisl malesuada. Donec sed dapibus nunc. Curabitur euismod erat a erat viverra vestibulum lacinia quis nisl. Aenean rhoncus suscipit maximus. Aliquam vitae lectus est. - -Sed rhoncus sem sapien, at posuere libero imperdiet eget. Maecenas in egestas quam. Duis non faucibus eros, nec sodales sem. Proin felis urna, dapibus eget ante vitae, porttitor bibendum nunc. Integer nec augue eget diam pulvinar vestibulum. Nulla lobortis libero tellus, eu commodo elit ullamcorper in. Sed semper ultricies turpis ac dignissim. Morbi at ligula non urna mollis interdum vitae sed nisi. Quisque mattis arcu eu nisl placerat ullamcorper. Cras aliquet risus sed hendrerit faucibus. Donec vitae ex quis magna cursus ultricies ut nec urna. - -Integer molestie nulla interdum enim suscipit malesuada. Nullam eget ipsum et elit sagittis imperdiet sed dignissim sem. Fusce vitae tellus ligula. Donec eget mi varius, consequat eros sed, consectetur urna. Suspendisse potenti. Praesent posuere ullamcorper tincidunt. Donec bibendum, magna nec mollis posuere, nisi risus dictum mauris, sed gravida metus sapien vel ipsum. Etiam ultrices nulla tincidunt erat lacinia, sit amet bibendum libero posuere. Vestibulum vehicula lectus dolor, sit amet vehicula arcu ultricies nec. Proin blandit risus diam, vel finibus erat efficitur in. Suspendisse lacinia eros luctus posuere fermentum. Etiam sed lacus aliquam, vulputate est sed, venenatis ex. Aenean at nulla rhoncus, sollicitudin elit quis, auctor tortor. Donec semper, augue lacinia pharetra imperdiet, metus purus bibendum ex, et venenatis enim purus vitae nulla. Duis eu felis porta ligula laoreet viverra. -Answer -It seems like you've used placeholder text commonly known as "Lorem Ipsum," which is often used in design and publishing to simulate the appearance of written text. If you have any specific questions or need assistance with something related to this text, feel free to ask! -what is its purpose? -Sources -solopress.com favicon -typingpal.com favicon -View 2 more -Answer -The purpose of Lorem Ipsum, a commonly used placeholder text in design and publishing, is to create a natural-looking block of text that doesn't distract from the layout. It allows designers to visualize how text will appear in a design without the need for actual content to be written and approved. Lorem Ipsum helps in planning out where the content will sit on a page, focusing on the design rather than the specific content. This practice is particularly useful when the main emphasis is on the visual layout, allowing designers and clients to review templates without being distracted by the actual copy on the page -4 -5 -. -hello -`; - export default function Main({ sidebarOpen }: { sidebarOpen: boolean }) { const searchParams = useSearchParams(); const router = useRouter(); @@ -290,10 +267,17 @@ export default function Main({ sidebarOpen }: { sidebarOpen: boolean }) { data-sidebar-open={sidebarOpen} ref={main} className={cn( - "sidebar flex w-full flex-col items-end justify-center gap-5 px-5 pt-5 transition-[padding-left,padding-top,padding-right] delay-200 duration-200 md:items-center md:gap-10 md:px-72 [&[data-sidebar-open='true']]:pr-10 [&[data-sidebar-open='true']]:delay-0 md:[&[data-sidebar-open='true']]:pl-[calc(2.5rem+30vw)]", + "sidebar relative flex w-full flex-col items-end justify-center gap-5 px-5 pt-5 transition-[padding-left,padding-top,padding-right] delay-200 duration-200 md:items-center md:gap-10 md:px-72 [&[data-sidebar-open='true']]:pr-10 [&[data-sidebar-open='true']]:delay-0 md:[&[data-sidebar-open='true']]:pl-[calc(2.5rem+30vw)]", hide ? "" : "main-hidden", )} > + Smort logo

Ask your second brain

diff --git a/apps/web/src/components/Sidebar/AddMemoryDialog.tsx b/apps/web/src/components/Sidebar/AddMemoryDialog.tsx index 5a1d92f0..784976b4 100644 --- a/apps/web/src/components/Sidebar/AddMemoryDialog.tsx +++ b/apps/web/src/components/Sidebar/AddMemoryDialog.tsx @@ -8,7 +8,8 @@ import { } from "../ui/dialog"; import { Input } from "../ui/input"; import { Label } from "../ui/label"; -import { useRef } from "react"; +import { Markdown } from "tiptap-markdown"; +import { useEffect, useRef, useState } from "react"; export function AddMemoryPage() { return ( @@ -39,23 +40,68 @@ export function AddMemoryPage() { ); } -export function NoteAddPage() { +export function NoteAddPage({ closeDialog }: { closeDialog: () => void }) { + const inputRef = useRef(null); + const [name, setName] = useState(""); + const [content, setContent] = useState(""); + const [loading, setLoading] = useState(false); + + function check() { + const data = { + name: name.trim(), + content, + }; + console.log(name); + if (!data.name || data.name.length < 1) { + if (!inputRef.current) { + alert("Please enter a name for the note"); + return; + } + inputRef.current.value = ""; + inputRef.current.placeholder = "Please enter a title for the note"; + inputRef.current.dataset["error"] = "true"; + setTimeout(() => { + inputRef.current!.placeholder = "Title of the note"; + inputRef.current!.dataset["error"] = "false"; + }, 500); + inputRef.current.focus(); + } + } + return ( <> setName(e.target.value)} /> { + if (!editor) return; + setContent(editor.storage.markdown.getMarkdown()); + }} + extensions={[Markdown]} className="novel-editor bg-rgray-4 border-rgray-7 dark mt-5 max-h-[60vh] min-h-[40vh] w-[50vw] overflow-y-auto rounded-lg border [&>div>div]:p-5" /> - + + Cancel diff --git a/apps/web/src/components/Sidebar/MemoriesBar.tsx b/apps/web/src/components/Sidebar/MemoriesBar.tsx index 83984233..92b1e210 100644 --- a/apps/web/src/components/Sidebar/MemoriesBar.tsx +++ b/apps/web/src/components/Sidebar/MemoriesBar.tsx @@ -62,7 +62,7 @@ export function MemoriesBar() { />
- +
); } diff --git a/apps/web/src/components/Sidebar/FilterCombobox.tsx b/apps/web/src/components/Sidebar/FilterCombobox.tsx index a8e3a1e5..04ff0324 100644 --- a/apps/web/src/components/Sidebar/FilterCombobox.tsx +++ b/apps/web/src/components/Sidebar/FilterCombobox.tsx @@ -30,6 +30,7 @@ export interface Props extends React.ButtonHTMLAttributes { setSelectedSpaces: ( spaces: number[] | ((prev: number[]) => number[]), ) => void; + name: string; } export function FilterCombobox({ @@ -39,10 +40,10 @@ export function FilterCombobox({ onClose, selectedSpaces, setSelectedSpaces, + name, ...props }: Props) { - const { spaces, addSpace } = useMemory(); - + const { spaces } = useMemory(); const [open, setOpen] = React.useState(false); const sortedSpaces = spaces.sort(({ id: a }, { id: b }) => @@ -65,6 +66,7 @@ export function FilterCombobox({ + + Cancel + + +
+ ); +} diff --git a/apps/web/src/server/db/schema.ts b/apps/web/src/server/db/schema.ts index e0ddbdbc..d78c0a89 100644 --- a/apps/web/src/server/db/schema.ts +++ b/apps/web/src/server/db/schema.ts @@ -88,6 +88,9 @@ export const storedContent = createTable( url: text("url").notNull(), savedAt: int("savedAt", { mode: "timestamp" }).notNull(), baseUrl: text("baseUrl", { length: 255 }), + type: text("type", { enum: ["note", "page", "twitter-bookmark"] }).default( + "page", + ), image: text("image", { length: 255 }), user: text("user", { length: 255 }).references(() => users.id), }, -- cgit v1.2.3 From 9b922304cf30deb3a0395d95b6f98d1a766c7bab Mon Sep 17 00:00:00 2001 From: Yash Date: Thu, 11 Apr 2024 06:29:18 +0000 Subject: clean url --- apps/web/src/components/ChatMessage.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'apps/web/src') diff --git a/apps/web/src/components/ChatMessage.tsx b/apps/web/src/components/ChatMessage.tsx index d25c9c48..db0778c4 100644 --- a/apps/web/src/components/ChatMessage.tsx +++ b/apps/web/src/components/ChatMessage.tsx @@ -37,7 +37,7 @@ export function ChatAnswer({ href={source} > - {source} + {cleanUrl(source)} ))}
@@ -103,3 +103,17 @@ function MessageSkeleton() {
); } + +function cleanUrl(url: string) { + if (url.startsWith("https://")) { + url = url.slice(8); + } else if (url.startsWith("http://")) { + url = url.slice(7); + } + + if (url.endsWith("/")) { + url = url.slice(0, -1); + } + + return url; +} -- cgit v1.2.3 From f9c34b7eeb74aadb3b2adab8d87637be9e68fa18 Mon Sep 17 00:00:00 2001 From: Yash Date: Thu, 11 Apr 2024 06:41:58 +0000 Subject: schema update --- apps/web/src/server/db/schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/web/src') diff --git a/apps/web/src/server/db/schema.ts b/apps/web/src/server/db/schema.ts index d78c0a89..ea90e5e9 100644 --- a/apps/web/src/server/db/schema.ts +++ b/apps/web/src/server/db/schema.ts @@ -121,7 +121,7 @@ export const space = createTable( "space", { id: integer("id").notNull().primaryKey({ autoIncrement: true }), - name: text("name").notNull().default("all"), + name: text("name").notNull().unique().default("none"), user: text("user", { length: 255 }).references(() => users.id), }, (space) => ({ -- cgit v1.2.3 From 22effd214c3bfa3e927604282da619bcc40b0d5f Mon Sep 17 00:00:00 2001 From: Dhravya Date: Thu, 11 Apr 2024 02:38:41 -0700 Subject: prepare statement --- apps/web/src/app/api/store/route.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/web/src') diff --git a/apps/web/src/app/api/store/route.ts b/apps/web/src/app/api/store/route.ts index ebe23077..ca6921c4 100644 --- a/apps/web/src/app/api/store/route.ts +++ b/apps/web/src/app/api/store/route.ts @@ -67,7 +67,7 @@ export async function POST(req: NextRequest) { let storeToSpace = data.space; if (!storeToSpace) { - storeToSpace = "all"; + storeToSpace = "none"; } const storedContentId = await db.insert(storedContent).values({ -- cgit v1.2.3 From bf99ee97f7c4d7580829d074816ebe0d32316d92 Mon Sep 17 00:00:00 2001 From: Yash Date: Thu, 11 Apr 2024 11:02:24 +0000 Subject: ok --- apps/web/src/actions/db.ts | 52 +++++++++ apps/web/src/components/Main.tsx | 6 +- .../web/src/components/Sidebar/AddMemoryDialog.tsx | 100 +++++++++-------- apps/web/src/components/Sidebar/FilterCombobox.tsx | 119 ++++++++++++++++++++- apps/web/src/components/Sidebar/MemoriesBar.tsx | 18 +++- apps/web/src/contexts/MemoryContext.tsx | 48 ++++++++- 6 files changed, 282 insertions(+), 61 deletions(-) create mode 100644 apps/web/src/actions/db.ts (limited to 'apps/web/src') diff --git a/apps/web/src/actions/db.ts b/apps/web/src/actions/db.ts new file mode 100644 index 00000000..3b640c96 --- /dev/null +++ b/apps/web/src/actions/db.ts @@ -0,0 +1,52 @@ +"use server"; +import { db } from "@/server/db"; +import { + contentToSpace, + StoredContent, + storedContent, +} from "@/server/db/schema"; +import { like, eq, and } from "drizzle-orm"; +import { auth as authOptions } from "@/server/auth"; +import { getSession } from "next-auth/react"; + +export async function getMemory(title: string) { + const session = await getSession(); + + console.log(session?.user?.name); + + if (!session || !session.user) { + return null; + } + + return await db + .select() + .from(storedContent) + .where( + and( + eq(storedContent.user, session.user.id!), + like(storedContent.title, `%${title}%`), + ), + ); +} + +export async function addMemory( + content: typeof storedContent.$inferInsert, + spaces: number[], +) { + const session = await getSession(); + + if (!session || !session.user) { + return null; + } + content.user = session.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; +} diff --git a/apps/web/src/components/Main.tsx b/apps/web/src/components/Main.tsx index 0235d608..c7bb3f1e 100644 --- a/apps/web/src/components/Main.tsx +++ b/apps/web/src/components/Main.tsx @@ -1,6 +1,6 @@ "use client"; import { useCallback, useEffect, useRef, useState } from "react"; -import { FilterCombobox } from "./Sidebar/FilterCombobox"; +import { FilterSpaces } from "./Sidebar/FilterCombobox"; import { Textarea2 } from "./ui/textarea"; import { ArrowRight, ArrowUp } from "lucide-react"; import { MemoryDrawer } from "./MemoryDrawer"; @@ -307,7 +307,7 @@ export default function Main({ sidebarOpen }: { sidebarOpen: boolean }) { }} >
- { textArea.current?.querySelector("textarea")?.focus(); @@ -383,7 +383,7 @@ export function Chat({ className="absolute flex w-full items-center justify-center" >
- { textArea.current?.querySelector("textarea")?.focus(); diff --git a/apps/web/src/components/Sidebar/AddMemoryDialog.tsx b/apps/web/src/components/Sidebar/AddMemoryDialog.tsx index aa86966f..886507ff 100644 --- a/apps/web/src/components/Sidebar/AddMemoryDialog.tsx +++ b/apps/web/src/components/Sidebar/AddMemoryDialog.tsx @@ -10,13 +10,17 @@ import { Input } from "../ui/input"; import { Label } from "../ui/label"; import { Markdown } from "tiptap-markdown"; import { useEffect, useRef, useState } from "react"; -import { FilterCombobox } from "./FilterCombobox"; +import { FilterSpaces } from "./FilterCombobox"; +import { useMemory } from "@/contexts/MemoryContext"; export function AddMemoryPage() { + const { addMemory } = useMemory(); + + const [url, setUrl] = useState(""); const [selectedSpacesId, setSelectedSpacesId] = useState([]); return ( -
+
Add a web page to memory @@ -30,25 +34,41 @@ export function AddMemoryPage() { type="url" data-modal-autofocus className="bg-rgray-4 mt-2 w-full" + value={url} + onChange={(e) => setUrl(e.target.value)} /> - - { + // @Dhravya this is adding a memory with insufficient information fix pls + await addMemory( + { + title: url, + content: "", + type: "page", + url: url, + image: "/icons/logo_without_bg.png", + savedAt: new Date(), + }, + selectedSpacesId, + ); + }} className="bg-rgray-4 hover:bg-rgray-5 focus-visible:bg-rgray-5 focus-visible:ring-rgray-7 rounded-md px-4 py-2 ring-transparent transition focus-visible:outline-none focus-visible:ring-2" > Add - + Cancel -
+ ); } @@ -60,16 +80,15 @@ export function NoteAddPage({ closeDialog }: { closeDialog: () => void }) { const [content, setContent] = useState(""); const [loading, setLoading] = useState(false); - function check() { + function check(): boolean { const data = { name: name.trim(), content, }; - console.log(name); if (!data.name || data.name.length < 1) { if (!inputRef.current) { alert("Please enter a name for the note"); - return; + return false; } inputRef.current.value = ""; inputRef.current.placeholder = "Please enter a title for the note"; @@ -79,7 +98,9 @@ export function NoteAddPage({ closeDialog }: { closeDialog: () => void }) { inputRef.current!.dataset["error"] = "false"; }, 500); inputRef.current.focus(); + return false; } + return true; } return ( @@ -87,7 +108,7 @@ export function NoteAddPage({ closeDialog }: { closeDialog: () => void }) { void }) { className="novel-editor bg-rgray-4 border-rgray-7 dark mt-5 max-h-[60vh] min-h-[40vh] w-[50vw] overflow-y-auto rounded-lg border [&>div>div]:p-5" /> - void }) { /> + Add + + Cancel diff --git a/apps/web/src/components/Sidebar/FilterCombobox.tsx b/apps/web/src/components/Sidebar/FilterCombobox.tsx index 04ff0324..0a93ee55 100644 --- a/apps/web/src/components/Sidebar/FilterCombobox.tsx +++ b/apps/web/src/components/Sidebar/FilterCombobox.tsx @@ -33,7 +33,124 @@ export interface Props extends React.ButtonHTMLAttributes { name: string; } -export function FilterCombobox({ +export function FilterSpaces({ + className, + side = "bottom", + align = "center", + onClose, + selectedSpaces, + setSelectedSpaces, + name, + ...props +}: Props) { + const { spaces } = useMemory(); + const [open, setOpen] = React.useState(false); + + const sortedSpaces = spaces.sort(({ id: a }, { id: b }) => + selectedSpaces.includes(a) && !selectedSpaces.includes(b) + ? -1 + : selectedSpaces.includes(b) && !selectedSpaces.includes(a) + ? 1 + : 0, + ); + + React.useEffect(() => { + if (!open) { + onClose?.(); + } + }, [open]); + + return ( + + + + + + + e.preventDefault()} + align={align} + side={side} + className="w-[200px] p-0" + > + + spaces + .find((s) => s.id.toString() === val) + ?.title.toLowerCase() + .includes(search.toLowerCase().trim()) + ? 1 + : 0 + } + > + + + + Nothing found + + {sortedSpaces.map((space) => ( + { + setSelectedSpaces((prev: number[]) => + prev.includes(parseInt(val)) + ? prev.filter((v) => v !== parseInt(val)) + : [...prev, parseInt(val)], + ); + }} + asChild + > + + + {space.title} + {selectedSpaces.includes(space.id)} + + + + ))} + + + + + + + + + ); +} + +export function FilterMemories({ className, side = "bottom", align = "center", diff --git a/apps/web/src/components/Sidebar/MemoriesBar.tsx b/apps/web/src/components/Sidebar/MemoriesBar.tsx index 3d7bd8b9..66c3138b 100644 --- a/apps/web/src/components/Sidebar/MemoriesBar.tsx +++ b/apps/web/src/components/Sidebar/MemoriesBar.tsx @@ -40,7 +40,7 @@ import { Label } from "../ui/label"; import useViewport from "@/hooks/useViewport"; import useTouchHold from "@/hooks/useTouchHold"; import { DialogTrigger } from "@radix-ui/react-dialog"; -import { AddMemoryPage, NoteAddPage } from "./AddMemoryDialog"; +import { AddMemoryPage, NoteAddPage, SpaceAddPage } from "./AddMemoryDialog"; export function MemoriesBar() { const [parent, enableAnimations] = useAutoAnimate(); @@ -91,10 +91,16 @@ export function MemoriesBar() { Note - - - Space - + + { + setAddMemoryState("space"); + }} + > + + Space + + @@ -343,6 +349,8 @@ export function AddMemoryModal({ ) : type === "note" ? ( setIsDialogOpen(false)} /> + ) : type === "space" ? ( + setIsDialogOpen(false)} /> ) : ( <> )} 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; + freeMemories: StoredContent[]; addSpace: (space: CollectedSpaces) => Promise; + addMemory: ( + memory: typeof storedContent.$inferInsert, + spaces?: number[], + ) => Promise; }>({ 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(initalSpaces); + const [freeMemories, setFreeMemories] = + React.useState(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 ( - + {children} ); -- cgit v1.2.3