Skip to content

Commit

Permalink
Merge pull request #8 from abhishekHegde2000/test-branch
Browse files Browse the repository at this point in the history
Add Note component and update NotesPage layout
  • Loading branch information
abhishekHegde2000 authored Nov 24, 2023
2 parents 4b2c915 + a5fc32e commit 395bb3a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/app/notes/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Note from "@/components/Note";
import prisma from "@/lib/db/prisma";
import { auth } from "@clerk/nextjs";
import { Metadata } from "next";
Expand All @@ -13,5 +14,16 @@ export default async function NotesPage() {

const allNotes = await prisma.note.findMany({ where: { userId } });

return <div>{JSON.stringify(allNotes)}</div>;
return (
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
{allNotes.map((note) => (
<Note note={note} key={note.id} />
))}
{allNotes.length === 0 && (
<div className="col-span-full text-center">
{"You don't have any notes yet. Why don't you create one?"}
</div>
)}
</div>
);
}
35 changes: 35 additions & 0 deletions src/components/Note.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Note as NoteModel } from "@prisma/client";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "./ui/card";

interface NoteProps {
note: NoteModel;
}

export default function Note({ note }: NoteProps) {
const wasUpdated = note.updatedAt > note.createdAt;

const createdUpdatedAtTimestamp = (
wasUpdated ? note.updatedAt : note.createdAt
).toDateString();

return (
<Card>
<CardHeader>
<CardTitle>{note.title}</CardTitle>
<CardDescription>
{createdUpdatedAtTimestamp}
{wasUpdated && " (updated)"}
</CardDescription>
</CardHeader>
<CardContent>
<p className="whitespace-pre-line">{note.content}</p>
</CardContent>
</Card>
);
}

0 comments on commit 395bb3a

Please sign in to comment.