From e6fc9c42278d979b155fd71b1f8f13e72c990208 Mon Sep 17 00:00:00 2001 From: Yash Date: Thu, 11 Apr 2024 01:34:49 +0000 Subject: ok --- .../web/src/components/Sidebar/AddMemoryDialog.tsx | 39 +++++ apps/web/src/components/Sidebar/MemoriesBar.tsx | 174 ++++++++++----------- 2 files changed, 120 insertions(+), 93 deletions(-) create mode 100644 apps/web/src/components/Sidebar/AddMemoryDialog.tsx (limited to 'apps/web/src/components/Sidebar') 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/components/Sidebar/index.tsx | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'apps/web/src/components/Sidebar') 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} ); -- 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 --- .../web/src/components/Sidebar/AddMemoryDialog.tsx | 31 ++++++++++++++-- apps/web/src/components/Sidebar/MemoriesBar.tsx | 42 ++++++++++------------ 2 files changed, 47 insertions(+), 26 deletions(-) (limited to 'apps/web/src/components/Sidebar') 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/Sidebar/index.tsx | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'apps/web/src/components/Sidebar') diff --git a/apps/web/src/components/Sidebar/index.tsx b/apps/web/src/components/Sidebar/index.tsx index 9e6bdcce..568aa3dd 100644 --- a/apps/web/src/components/Sidebar/index.tsx +++ b/apps/web/src/components/Sidebar/index.tsx @@ -77,24 +77,16 @@ export default function Sidebar({ <>
- - ), - labelDisplay: , - }} - selectedItem={selectedItem} - setSelectedItem={setSelectedItem} + Smort logo +
+ -
- Date: Thu, 11 Apr 2024 05:57:42 +0000 Subject: notess --- .../web/src/components/Sidebar/AddMemoryDialog.tsx | 60 +++++++++++++++++++--- apps/web/src/components/Sidebar/MemoriesBar.tsx | 12 +++-- apps/web/src/components/Sidebar/index.tsx | 12 ----- 3 files changed, 60 insertions(+), 24 deletions(-) (limited to 'apps/web/src/components/Sidebar') 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 + + +
+ ); +} -- 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 --- .../web/src/components/Sidebar/AddMemoryDialog.tsx | 100 +++++++++-------- apps/web/src/components/Sidebar/FilterCombobox.tsx | 119 ++++++++++++++++++++- apps/web/src/components/Sidebar/MemoriesBar.tsx | 18 +++- 3 files changed, 184 insertions(+), 53 deletions(-) (limited to 'apps/web/src/components/Sidebar') 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)} /> ) : ( <> )} -- cgit v1.2.3