-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add note modifying functionality, dynamic route caching adjustments a…
…nd 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
- Loading branch information
1 parent
f42deba
commit be319b7
Showing
21 changed files
with
874 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<div className="relative h-screen w-full"> | ||
{children} | ||
<div className="absolute bottom-6 left-1/2 -translate-x-1/2"> | ||
<Menubar> | ||
<MenubarMenu> | ||
<MenubarTrigger>File</MenubarTrigger> | ||
<MenubarContent> | ||
<MenubarItem>Save raster output</MenubarItem> | ||
</MenubarContent> | ||
</MenubarMenu> | ||
<MenubarMenu> | ||
<MenubarTrigger>View</MenubarTrigger> | ||
<MenubarContent> | ||
<MenubarItem>2D</MenubarItem> | ||
<MenubarSeparator /> | ||
<MenubarItem>3D</MenubarItem> | ||
</MenubarContent> | ||
</MenubarMenu> | ||
</Menubar> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function MapPage() { | ||
return ( | ||
<main> | ||
<h2>Map</h2> | ||
</main> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Awaited<ReturnType<typeof getNote>>>; // 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 ( | ||
<div className="flex h-full min-h-screen divide-x"> | ||
<div className="flex w-full flex-col gap-6 p-6"> | ||
<input | ||
className="text-4xl font-bold outline-none" | ||
value={title} | ||
onChange={(e) => { | ||
setTitle(e.target.value); | ||
debouncedUpdateNoteTitle(note.id, { | ||
title: e.target.value, | ||
}); | ||
}} | ||
/> | ||
<textarea | ||
className="h-96 resize-none text-lg outline-none" | ||
value={content} | ||
placeholder="Write your note here..." | ||
onChange={(e) => { | ||
setContent(e.target.value); | ||
debouncedUpdateNoteContent(note.id, { | ||
content: e.target.value, | ||
}); | ||
}} | ||
/> | ||
</div> | ||
<div className="flex w-80 flex-col items-stretch gap-4 bg-slate-100/50 p-6"> | ||
<span className="block text-sm text-slate-400">Note actions</span> | ||
<Button | ||
className="w-full justify-start" | ||
variant={"destructive"} | ||
onClick={handleDeleteNote} | ||
> | ||
<TrashIcon className="mr-3" /> | ||
Delete note | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,43 @@ | ||
import { Metadata } from "next"; | ||
import { redirect } from "next/navigation"; | ||
|
||
import { getNote } from "@/helpers/notes/getNote"; | ||
|
||
export default async function EditNotePage({ | ||
params, | ||
}: { | ||
import NoteEditor from "./note-editor"; | ||
|
||
type Props = { | ||
params: { noteId: string }; | ||
}) { | ||
}; | ||
|
||
export async function generateMetadata({ params }: Props): Promise<Metadata> { | ||
const { noteId } = params; | ||
const note = await getNote(noteId); | ||
|
||
if (!note) { | ||
return { | ||
title: "Note not found", | ||
}; | ||
} | ||
|
||
return { | ||
title: `Edit note: ${note.title}`, | ||
}; | ||
} | ||
|
||
export default async function EditNotePage({ params }: Props) { | ||
const { noteId } = params; | ||
const note = await getNote(noteId); | ||
|
||
if (!note || note.deleted) { | ||
redirect("/notes"); | ||
} | ||
|
||
return ( | ||
<main> | ||
<h1>Edit note</h1> | ||
<pre> | ||
<code>{JSON.stringify(note, null, 2)}</code> | ||
</pre> | ||
<NoteEditor note={note} /> | ||
</main> | ||
); | ||
} | ||
|
||
export const dynamic = "force-dynamic"; | ||
export const fetchCache = "force-no-store"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.