feat: add note copy

This commit is contained in:
Kirill Siukhin 2025-07-15 22:47:36 +05:00
parent 49f7c8253e
commit 5da589c331
2 changed files with 15 additions and 2 deletions

View File

@ -15,7 +15,7 @@ export async function createNote() {
.returning({ id: usersTable.id }); .returning({ id: usersTable.id });
const noteId = result[0].id; const noteId = result[0].id;
await db.insert(blocksTable).values({ noteId }); await db.insert(blocksTable).values({ noteId, order: 1 });
redirect(`/notes/${noteId}`); redirect(`/notes/${noteId}`);
} }

View File

@ -1,3 +1,5 @@
"use client";
import { Copy, Plus } from "lucide-react"; import { Copy, Plus } from "lucide-react";
import { v4 as uuidv4 } from "uuid"; import { v4 as uuidv4 } from "uuid";
import { IBlock, INote } from "@/lib/db/schema"; import { IBlock, INote } from "@/lib/db/schema";
@ -33,6 +35,17 @@ export default function Editor({
note?: INote; note?: INote;
blocks?: IBlock[]; 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 ( return (
<div className="flex flex-col items-center max-w-2xl w-full gap-4"> <div className="flex flex-col items-center max-w-2xl w-full gap-4">
<input <input
@ -45,7 +58,7 @@ export default function Editor({
<input type="hidden" name="noteId" value={note.id} /> <input type="hidden" name="noteId" value={note.id} />
<IconOnlyButton icon={<Plus size={24} />} type="submit" /> <IconOnlyButton icon={<Plus size={24} />} type="submit" />
</form> </form>
<IconOnlyButton icon={<Copy size={24} />} title="Copy note to clipboard" /> <IconOnlyButton icon={<Copy size={24} />} onClick={copyHandler} title="Copy note to clipboard" />
</div> </div>
</div> </div>
); );