import { Todo, User, UserWithTodos } from '@homeman/models.ts' import { Signal, useSignal } from '@preact/signals' import { TodoList } from '@homeman/islands/TodoList.tsx' import { Dialog } from '@homeman/components/Dialog.tsx' import { Label } from '@homeman/components/Label.tsx' import { Input } from '@homeman/components/Input.tsx' import { Avatar } from '@homeman/components/Avatar.tsx' import { Button } from '@homeman/components/Button.tsx' import { JSX } from 'preact' import { useEffect } from 'preact/hooks' import { excitement } from '@homeman/common.ts' interface Props { users: Record todos: Record unassignedTodos: Todo[] lastUserIdUpdated: { value: string; versionstamp: string } lastTodoIdUpdated: { value: string; versionstamp: string } } const unassignedUserPlaceholder: User = { id: '', createdAt: new Date(), name: 'Shared', avatarUrl: 'http://placekitten.com/512/512', color: '888888', } interface UserSelectButtonProps extends JSX.HTMLAttributes { user: User } function UserSelectButton( { user: { id, name, avatarUrl, color }, tabindex, ...props }: UserSelectButtonProps, ) { const eid = `assigneeUserId_${id}` return ( <> ) } export default function Dashboard( props: Props, ) { const todoAssignUserId: Signal = useSignal(null) const showAddTodoDialog = useSignal(false) const data = useSignal(props) const { // todos, users, unassignedTodos, // lastTodoIdUpdated, // lastUserIdUpdated, } = data.value const reload = async () => { console.log('reloading...') const newData = await (await fetch(location.href, { headers: { accept: 'application/json' }, })).json() data.value = newData console.log('new data:', newData) } useEffect(() => { let es = new EventSource('/api/user') es.addEventListener('message', async (e) => { console.log('user event stream message:', e) await reload() excitement() }) es.addEventListener('error', async (e) => { // try and reconnect console.log('Streaming user events error:', e) es.close() const backoff = 10000 + Math.random() * 5000 await new Promise((resolve) => setTimeout(resolve, backoff)) es = new EventSource('/api/user') }) }, []) useEffect(() => { let es = new EventSource('/api/todo') console.log('Streaming todo events...') es.addEventListener('message', (e) => { console.log('todo event from server:', e) reload().then(excitement) }) es.addEventListener('error', async (e) => { // try and reconnect console.log('Streaming todo events error:', e) es.close() const backoff = 10000 + Math.random() * 5000 await new Promise((resolve) => setTimeout(resolve, backoff)) es = new EventSource('/api/todo') }) }, []) const unassignedUser: UserWithTodos = { ...unassignedUserPlaceholder, assignedTodos: unassignedTodos, } return (
showAddTodoDialog.value = false} >
Assignee
  • {Object.values(users).map( (user) => { return (
  • ) }, )}

Todos

  • { console.log('shared new') showAddTodoDialog.value = true todoAssignUserId.value = null }} user={unassignedUser} />
  • {Object.values(users).map((u) => (
  • { showAddTodoDialog.value = true todoAssignUserId.value = u.id }} user={u} />
  • ))}
) }