import { createRef } from 'preact' import { type Signal, useSignal } from '@preact/signals' import { Todo, User } from '@homeman/models.ts' import { Button } from '@homeman/components/Button.tsx' import { Input } from '@homeman/components/Input.tsx' import { Label } from '@homeman/components/Label.tsx' export interface Props { users: User[] todos: Todo[] } async function promptDeleteUser(id: string, name: string) { if (confirm(`Are you sure you want to delete ${name} (${id})?`)) { await fetch(`/api/user?id=${id}`, { method: 'DELETE' }) location.reload() } } export function Admin({ users, todos }: Props) { const editUser: Signal = useSignal(null) const addUserDialog = createRef() const editUserDialog = createRef() const usersById: Record = {} for (const u of users) { usersById[u.id] = u } return (

Add user

console.log('Submitting new user...')} >

{`Edit '${editUser.value?.name}'`}

console.log('Submitting edit user...')} >

Users ({users.length})

{users.map((user) => { const { id, name, avatarUrl, color } = user return ( ) })}
Name Avatar Color Actions
{name} {avatarUrl == null ? 'None' : } #{color}

Todos ({todos.length})

{todos.map(({ description, assigneeUserId }) => ( ))}
Description Assignee
{description} {assigneeUserId == null ? 'Unassigned' : usersById[assigneeUserId]?.name}
) }