homeman-deno/routes/index.tsx

53 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-01-05 21:10:38 -06:00
import { Handlers, PageProps } from '$fresh/server.ts'
2024-01-07 02:24:36 -06:00
import { db, Todo, User, UserWithTodos } from '@homeman/models.ts'
import { TodoList } from '@homeman/components/TodoList.tsx'
const unassignedUserPlaceholder: User = {
id: '',
createdAt: new Date(),
name: 'Shared',
avatarUrl: 'http://placekitten.com/512/512',
color: '888888',
}
2024-01-05 13:22:56 -06:00
interface Data {
2024-01-07 02:24:36 -06:00
users: UserWithTodos[]
2024-01-05 21:10:38 -06:00
unassignedTodos: Todo[]
2024-01-05 13:22:56 -06:00
}
export const handler: Handlers = {
async GET(_req, ctx) {
2024-01-05 21:10:38 -06:00
const users = await db.users.findMany({ include: { assignedTodos: true } })
const unassignedTodos = await db.todos.findMany({
where: { assigneeUserId: null },
})
return ctx.render({ users, unassignedTodos })
2024-01-05 13:22:56 -06:00
},
}
2024-01-06 23:53:44 -06:00
export default function Home(
{ data: { users, unassignedTodos } }: PageProps<Data>,
) {
2024-01-07 02:24:36 -06:00
const unassignedUser: UserWithTodos = {
...unassignedUserPlaceholder,
assignedTodos: unassignedTodos,
}
2024-01-05 13:22:56 -06:00
return (
2024-01-07 02:24:36 -06:00
<main class='flex flex-col'>
<h1 class='p-5 border-b-2 border-stone-500/20 text-2xl'>
Todos
</h1>
<ul class='p-4 relative'>
<li>
<TodoList user={unassignedUser} />
</li>
{users.map((u) => (
<li>
<TodoList user={u} />
</li>
))}
</ul>
</main>
2024-01-05 13:22:56 -06:00
)
}