homeman-deno/islands/Admin.tsx

78 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-01-07 02:24:36 -06:00
import { createRef } from 'preact'
import { Todo, User } from '@homeman/models.ts'
import { Button } from '@homeman/components/Button.tsx'
export interface Props {
users: User[]
todos: Todo[]
}
export function Admin({ users, todos }: Props) {
const addUserDialog = createRef<HTMLDialogElement>()
const usersById: Record<string, User> = {}
for (const u of users) {
usersById[u.id] = u
}
return (
<main class='flex flex-col'>
<dialog ref={addUserDialog}>sup</dialog>
<header class='flex items-center border-b-2 border-stone-500/20 '>
<h1 class='p-5 text-2xl'>
Users ({users.length})
</h1>
<Button onClick={() => addUserDialog.current?.showModal()}>
Add User
</Button>
</header>
<table class='border-separate [border-spacing:1.25rem] text-left'>
<thead>
<tr>
<th>Name</th>
<th>Avatar</th>
<th>Color</th>
</tr>
</thead>
<tbody>
{users.map(({ name, avatarUrl, color }) => (
<tr>
<td>{name}</td>
<td>
{avatarUrl == null ? 'None' : <img class='' src={avatarUrl} />}
</td>
<td>
#{color}
</td>
</tr>
))}
</tbody>
</table>
<header class='flex items-center border-b-2 border-stone-500/20 '>
<h1 class='p-5 text-2xl'>
Todos ({users.length})
</h1>
<Button>+</Button>
</header>
<table class='border-separate [border-spacing:1.25rem] text-left'>
<thead>
<tr>
<th>Description</th>
<th>Assignee</th>
</tr>
</thead>
<tbody>
{todos.map(({ description, assigneeUserId }) => (
<tr>
<td>{description}</td>
<td>
{assigneeUserId == null
? 'Unassigned'
: usersById[assigneeUserId]?.name}
</td>
</tr>
))}
</tbody>
</table>
</main>
)
}