-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathpage.tsx
More file actions
60 lines (53 loc) · 1.87 KB
/
page.tsx
File metadata and controls
60 lines (53 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { prisma } from '@/lib/prisma';
import { getAuthSession } from '@/lib/auth';
import TodoItemComponent from './components/TodoItem';
import CreateTodoForm from './components/CreateTodoForm';
import { TodoItemStatus } from '@prisma/client';
import Header from '@/components/Header';
export default async function Home() {
const { userId } = await getAuthSession();
const todos = await prisma.todoItem.findMany({
where: {
userId,
},
orderBy: {
createdAt: 'desc',
},
});
const pendingTodos = todos.filter((todo) => todo.status === TodoItemStatus.PENDING);
const completedTodos = todos.filter((todo) => todo.status === TodoItemStatus.COMPLETED);
return (
<div className="min-h-screen flex flex-col">
<Header />
<main className="flex-grow">
<div className="max-w-4xl mx-auto px-4 py-8">
<CreateTodoForm userId={userId} />
<div className="mb-8">
<h2 className="text-xl font-semibold mb-4">Pending Tasks ({pendingTodos.length})</h2>
{pendingTodos.length === 0 ? (
<p className="text-gray-500 text-center py-4">No pending tasks. Great job!</p>
) : (
<div>
{pendingTodos.map((todo) => (
<TodoItemComponent key={todo.id} todo={todo} />
))}
</div>
)}
</div>
<div>
<h2 className="text-xl font-semibold mb-4">Completed Tasks ({completedTodos.length})</h2>
{completedTodos.length === 0 ? (
<p className="text-gray-500 text-center py-4">No completed tasks yet.</p>
) : (
<div>
{completedTodos.map((todo) => (
<TodoItemComponent key={todo.id} todo={todo} />
))}
</div>
)}
</div>
</div>
</main>
</div>
);
}