Connected notes
{noteRelations.length === 0 ? (
@@ -83,8 +83,8 @@ export default function NoteActions({ note }: Props) {
variant={"link"}
size={"sm"}
>
- {relatedNote.title.length > 32
- ? `${relatedNote.title.slice(0, 32)}...`
+ {relatedNote.title.length > 20
+ ? `${relatedNote.title.slice(0, 20)}...`
: relatedNote.title}
diff --git a/app/(platform)/notes/notes-pagination.tsx b/app/(platform)/notes/notes-pagination.tsx
index 0b9a123..43b0e8d 100644
--- a/app/(platform)/notes/notes-pagination.tsx
+++ b/app/(platform)/notes/notes-pagination.tsx
@@ -32,6 +32,7 @@ export default function NotesPagination({
const prevPageHref = `${path}?page=${currentPage - 1}`;
const nextPageHref = `${path}?page=${currentPage + 1}`;
+ const lastPageHref = `${path}?page=${totalPages}`;
return (
@@ -51,11 +52,6 @@ export default function NotesPagination({
{currentPage}
- {totalPages && totalPages > currentPage + 2 && (
-
-
-
- )}
{isThereANextPage && (
<>
@@ -63,6 +59,13 @@ export default function NotesPagination({
{currentPage + 1}
+ {totalPages && totalPages > currentPage + 2 && (
+
+
+
+
+
+ )}
diff --git a/package.json b/package.json
index 9f6a2d3..2ce36f6 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,8 @@
"test": "vitest --passWithNoTests",
"lint": "next lint --fix",
"prepare": "husky",
- "prettier": "prettier --write ."
+ "prettier": "prettier --write .",
+ "seed": "npx ts-node prisma/seed.ts"
},
"dependencies": {
"@clerk/nextjs": "^4.29.9",
diff --git a/prisma/seed.ts b/prisma/seed.ts
new file mode 100644
index 0000000..e491506
--- /dev/null
+++ b/prisma/seed.ts
@@ -0,0 +1,82 @@
+const { PrismaClient } = require("@prisma/client");
+
+const prisma = new PrismaClient();
+
+const topics = [
+ "concerts",
+ "painting",
+ "cat",
+ "creative coding",
+ "groceries",
+ "cooking",
+ "planning trips",
+ "running",
+ "bouldering",
+ "listening to and discovering new music",
+ "reading",
+ "socialising",
+ "buying gifts",
+ "shopping for clothes",
+ "watching movies",
+];
+
+const TEST_USER_ID = process.env.TEST_USER_ID;
+const SEED_COUNT = 200;
+
+async function seedDatabase() {
+ console.log(`Seeding database for user ${TEST_USER_ID}...`);
+
+ try {
+ // Clear current notes
+ await prisma.note.deleteMany({
+ where: {
+ authorId: TEST_USER_ID,
+ },
+ });
+
+ for (let i = 0; i < SEED_COUNT; i++) {
+ const title = topics[Math.floor(Math.random() * topics.length)];
+ const content =
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
+ const authorId = TEST_USER_ID as string;
+
+ // Randomly decide if the note should connect to others
+ let relatedNotes = undefined;
+ if (Math.random() < 0.8) {
+ // Determine how many notes to connect to (1-5 randomly)
+ const numRelated = Math.floor(Math.random() * 5) + 1;
+ // Find numRelated random notes that already exist in the database
+ const randomNotes = await prisma.note.findMany({
+ take: numRelated,
+ skip: Math.floor(Math.random() * i), // Randomly skip existing notes
+ });
+ relatedNotes = {
+ // @ts-ignore
+ connect: randomNotes.map((note) => ({ id: note.id })),
+ };
+ }
+
+ const note = await prisma.note.create({
+ data: {
+ title: title,
+ content: content,
+ authorId: authorId,
+ relatedNotes: relatedNotes,
+ },
+ });
+
+ console.log(
+ `[${i + 1} / ${SEED_COUNT}] - `,
+ `Created note with id: ${note.id}`
+ );
+ }
+
+ console.log("Database seeded successfully.");
+ } catch (error) {
+ console.error("Error seeding database:", error);
+ } finally {
+ await prisma.$disconnect();
+ }
+}
+
+seedDatabase();