diff --git a/src/app/(editor)/layout.tsx b/src/app/(editor)/layout.tsx
deleted file mode 100644
index e2e6109..0000000
--- a/src/app/(editor)/layout.tsx
+++ /dev/null
@@ -1,14 +0,0 @@
-import Header from "@/components/Header";
-
-export default function RootLayout({
- children,
-}: Readonly<{
- children: React.ReactNode;
-}>) {
- return (
- <>
-
- {children}
- >
- );
-}
diff --git a/src/app/(noneditor)/layout.tsx b/src/app/(noneditor)/layout.tsx
deleted file mode 100644
index 311c52a..0000000
--- a/src/app/(noneditor)/layout.tsx
+++ /dev/null
@@ -1,16 +0,0 @@
-import Header from "@/components/Header";
-
-export default function RootLayout({
- children,
-}: Readonly<{
- children: React.ReactNode;
-}>) {
- return (
- <>
-
-
diff --git a/src/components/editor/Editor.tsx b/src/components/editor/Editor.tsx
index dce59c7..0c925de 100644
--- a/src/components/editor/Editor.tsx
+++ b/src/components/editor/Editor.tsx
@@ -1,7 +1,7 @@
"use client";
import { useReducer } from "react";
-import { Plus } from "lucide-react";
+import { Copy, Plus } from "lucide-react";
import { editorReducer } from "@/lib/editorReducer";
import IconOnlyButton from "../ui/IconOnlyButton";
import Block from "./Block";
@@ -23,11 +23,18 @@ export default function Editor() {
dispatch({ type: "add_block" });
}
+ const handleCopy = () => {
+ dispatch({ type: "copy" });
+ }
+
return (
{state.map((block) =>
)}
-
} />
+
+ } />
+ } title="Copy note to clipboard" />
+
);
}
diff --git a/src/components/ui/NoteCard.tsx b/src/components/ui/NoteCard.tsx
index 27e3bdc..b0c2ac4 100644
--- a/src/components/ui/NoteCard.tsx
+++ b/src/components/ui/NoteCard.tsx
@@ -5,6 +5,15 @@ import { notesTable } from "@/lib/db/schema";
import { deleteNote } from "@/lib/notes";
import IconOnlyButton from "./IconOnlyButton";
+function makeTimestamp(date: Date) {
+ const day = date.getDate();
+ const month = date.getMonth() + 1;
+ const year = date.getFullYear();
+ const hours = date.getHours();
+ const minutes = date.getMinutes();
+ return `${day}.${month}.${year} ${hours}:${minutes}`;
+}
+
export default function NoteCard({ note }: { note: typeof notesTable.$inferSelect }) {
const handleDeleteNote = async () => {
"use server";
@@ -13,11 +22,11 @@ export default function NoteCard({ note }: { note: typeof notesTable.$inferSelec
}
return (
-
-
+
+
{note.name}
- Creation date: {note.creationTime.toString()}
- Last time edited: {note.lastEdited.toString()}
+ Last time edited: {makeTimestamp(note.lastEdited)}
+ Creation date: {makeTimestamp(note.creationTime)}
} onClick={handleDeleteNote} />
diff --git a/src/lib/editorReducer.ts b/src/lib/editorReducer.ts
index 8cd7004..c1ec579 100644
--- a/src/lib/editorReducer.ts
+++ b/src/lib/editorReducer.ts
@@ -14,6 +14,7 @@ type EditorState = IBlock[];
export type Action =
| { type: "add_block" }
+ | { type: "copy" }
| { type: "delete_block", blockId: string }
| { type: "add_line", blockId: string }
| { type: "delete_line", blockId: string }
@@ -36,6 +37,21 @@ export function editorReducer(state: EditorState, action: Action): EditorState {
})),
}
];
+
+ case "copy":
+ let copyText = "";
+
+ state.forEach((block) => {
+ if (block.tag !== "") {
+ copyText += `[${block.tag}]\n`;
+ }
+
+ block.lines.forEach((line) => copyText += line.text + "\n")
+ copyText += "\n";
+ });
+
+ navigator.clipboard.writeText(copyText);
+ return state;
case "delete_block":
return state.filter((block) => block.id !== action.blockId);
diff --git a/src/lib/notes.ts b/src/lib/notes.ts
index 7a095f3..0ee1727 100644
--- a/src/lib/notes.ts
+++ b/src/lib/notes.ts
@@ -1,17 +1,13 @@
-import { eq } from "drizzle-orm";
+import { desc, eq } from "drizzle-orm";
import { notesTable } from "./db/schema";
import { getAuth } from "./auth";
import { db } from "./db";
-export async function getNotes() {
- const auth = await getAuth();
- if (!auth) {
- return null;
- }
-
+export async function getNotes(authorId: string) {
return db.select()
.from(notesTable)
- .where(eq(notesTable.authorId, auth.id));
+ .where(eq(notesTable.authorId, authorId))
+ .orderBy(desc(notesTable.lastEdited));
}
export async function createNote() {