From be319b7c2824713aaaaf452e36efacb55fec6d93 Mon Sep 17 00:00:00 2001 From: bercivarga <65171545+bercivarga@users.noreply.github.com> Date: Sat, 9 Mar 2024 23:00:51 +0100 Subject: [PATCH] Add note modifying functionality, dynamic route caching adjustments and map page(s) preparations (#4) * add base note helpers for modifying relations and content * add note-editor base * add force dynamic rendering logic to notes page * add note deletion functionality * add better revalidation to dynamic pages * add preparations for map pages --- app/(platform)/dashboard/page.tsx | 9 +- app/(platform)/layout.tsx | 2 +- app/(platform)/map/layout.tsx | 45 +++ app/(platform)/map/page.tsx | 7 + app/(platform)/notes/[noteId]/note-editor.tsx | 76 +++++ app/(platform)/notes/[noteId]/page.tsx | 34 +- app/(platform)/notes/new/route.ts | 2 +- app/(platform)/notes/page.tsx | 26 +- app/(platform)/side-nav.tsx | 6 +- components/ui/menubar.tsx | 243 ++++++++++++++ helpers/notes/addTag.ts | 32 ++ helpers/notes/connectNotes.ts | 18 ++ helpers/notes/deleteNote.ts | 4 + helpers/notes/disconnectNotes.ts | 18 ++ helpers/notes/getAllNotes.ts | 5 +- helpers/notes/getNote.ts | 2 - helpers/notes/removeTag.ts | 18 ++ helpers/notes/updateNoteContent.ts | 25 ++ helpers/notes/updateNoteTitle.ts | 25 ++ package-lock.json | 302 ++++++++++++++++++ package.json | 3 + 21 files changed, 874 insertions(+), 28 deletions(-) create mode 100644 app/(platform)/map/layout.tsx create mode 100644 app/(platform)/map/page.tsx create mode 100644 app/(platform)/notes/[noteId]/note-editor.tsx create mode 100644 components/ui/menubar.tsx create mode 100644 helpers/notes/addTag.ts create mode 100644 helpers/notes/connectNotes.ts create mode 100644 helpers/notes/disconnectNotes.ts create mode 100644 helpers/notes/removeTag.ts create mode 100644 helpers/notes/updateNoteContent.ts create mode 100644 helpers/notes/updateNoteTitle.ts diff --git a/app/(platform)/dashboard/page.tsx b/app/(platform)/dashboard/page.tsx index fcca5a7..d7ce7ba 100644 --- a/app/(platform)/dashboard/page.tsx +++ b/app/(platform)/dashboard/page.tsx @@ -7,9 +7,12 @@ export const metadata: Metadata = { export default function Home() { return ( -
-

Dashboard

-

hi

+
+

Dashboard

+

+ Welcome to your dashboard. This is where you can start working on your + ideas. You can create new notes, view your recent notes, and more. +

); } diff --git a/app/(platform)/layout.tsx b/app/(platform)/layout.tsx index 1d90566..87ec0b6 100644 --- a/app/(platform)/layout.tsx +++ b/app/(platform)/layout.tsx @@ -8,7 +8,7 @@ export default function RootLayout({ return (
-
{children}
+
{children}
); } diff --git a/app/(platform)/map/layout.tsx b/app/(platform)/map/layout.tsx new file mode 100644 index 0000000..d6f09e4 --- /dev/null +++ b/app/(platform)/map/layout.tsx @@ -0,0 +1,45 @@ +import { Metadata } from "next"; + +import { + Menubar, + MenubarContent, + MenubarItem, + MenubarMenu, + MenubarSeparator, + MenubarTrigger, +} from "@/components/ui/menubar"; + +export const metadata: Metadata = { + title: "Map", + description: "Map", +}; + +export default function MapLayout({ + children, +}: Readonly<{ + children: React.ReactNode; +}>) { + return ( +
+ {children} +
+ + + File + + Save raster output + + + + View + + 2D + + 3D + + + +
+
+ ); +} diff --git a/app/(platform)/map/page.tsx b/app/(platform)/map/page.tsx new file mode 100644 index 0000000..77c026d --- /dev/null +++ b/app/(platform)/map/page.tsx @@ -0,0 +1,7 @@ +export default function MapPage() { + return ( +
+

Map

+
+ ); +} diff --git a/app/(platform)/notes/[noteId]/note-editor.tsx b/app/(platform)/notes/[noteId]/note-editor.tsx new file mode 100644 index 0000000..1ce3c23 --- /dev/null +++ b/app/(platform)/notes/[noteId]/note-editor.tsx @@ -0,0 +1,76 @@ +"use client"; + +import { TrashIcon } from "@radix-ui/react-icons"; +import debounce from "lodash.debounce"; +import { useRouter } from "next/navigation"; +import { useState } from "react"; + +import { Button } from "@/components/ui/button"; +import { deleteNote } from "@/helpers/notes/deleteNote"; +import { getNote } from "@/helpers/notes/getNote"; +import { updateNoteContent } from "@/helpers/notes/updateNoteContent"; +import { updateNoteTitle } from "@/helpers/notes/updateNoteTitle"; + +type Props = { + note: NonNullable>>; // I love TS +}; + +const debounceDelay = 500; +const debouncedUpdateNoteTitle = debounce(updateNoteTitle, debounceDelay); +const debouncedUpdateNoteContent = debounce(updateNoteContent, debounceDelay); + +export default function NoteEditor({ note }: Props) { + const [title, setTitle] = useState(note.title); + const [content, setContent] = useState(note.content); + + const router = useRouter(); + + async function handleDeleteNote() { + const deletedNote = await deleteNote(note.id); + if (!deletedNote) { + alert("Failed to delete note"); // TODO: better error handling with a toast + return; + } + + router.push("/notes"); + } + + return ( +
+
+ { + setTitle(e.target.value); + debouncedUpdateNoteTitle(note.id, { + title: e.target.value, + }); + }} + /> +