From 5da589c331b06a9c348d06ad406581d9b5cf5407 Mon Sep 17 00:00:00 2001 From: misterkirill Date: Tue, 15 Jul 2025 22:47:36 +0500 Subject: [PATCH] feat: add note copy --- src/app/actions/notes.ts | 2 +- src/components/editor/Editor.tsx | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/app/actions/notes.ts b/src/app/actions/notes.ts index 404e957..be8f6c3 100644 --- a/src/app/actions/notes.ts +++ b/src/app/actions/notes.ts @@ -15,7 +15,7 @@ export async function createNote() { .returning({ id: usersTable.id }); const noteId = result[0].id; - await db.insert(blocksTable).values({ noteId }); + await db.insert(blocksTable).values({ noteId, order: 1 }); redirect(`/notes/${noteId}`); } diff --git a/src/components/editor/Editor.tsx b/src/components/editor/Editor.tsx index 6827086..143b3b5 100644 --- a/src/components/editor/Editor.tsx +++ b/src/components/editor/Editor.tsx @@ -1,3 +1,5 @@ +"use client"; + import { Copy, Plus } from "lucide-react"; import { v4 as uuidv4 } from "uuid"; import { IBlock, INote } from "@/lib/db/schema"; @@ -33,6 +35,17 @@ export default function Editor({ note?: INote; blocks?: IBlock[]; }) { + const copyHandler = () => { + let copyText = ""; + blocks.forEach((block) => { + if (block.tag !== "") { + copyText += `[${block.tag}]`; + } + copyText += block.lines.join("\n"); + }); + navigator.clipboard.writeText(copyText); + } + return (
} type="submit" /> - } title="Copy note to clipboard" /> + } onClick={copyHandler} title="Copy note to clipboard" />
);