import { Todo, UserWithTodos } from '@homeman/models.ts' import { JSX } from 'preact' import { Button } from '@homeman/components/Button.tsx' import { Avatar } from '@homeman/components/Avatar.tsx' import { ChevronDoubleDownOutline, ChevronDownOutline } from 'preact-heroicons' import { ChevronDownMiniSolid } from 'preact-heroicons' export interface Props { user: UserWithTodos onNewButtonClicked: JSX.MouseEventHandler onTodoDone: (id: string) => Promise } export function TodoList( { onTodoDone, onNewButtonClicked, user: { avatarUrl, name, color, ...user } }: Props, ) { const doneTodos = user.assignedTodos.filter((t) => t.doneAt != null) const inProgressTodos = user.assignedTodos.filter((t) => t.doneAt == null) const todoItem = ( { id, doneAt, className, description, hideDone }: & Pick & { className?: string hideDone?: boolean }, ) => (
  • {description} {(hideDone || doneAt != null) ? '' : ( )} {(!hideDone && doneAt != null) ? ( ) : ''}
  • ) return (
    {name}
      {inProgressTodos.length < 1 ? todoItem({ id: '', doneAt: null, description: 'All clear! 🎉', className: 'text-center', hideDone: true, }) : inProgressTodos.map(todoItem)}
    {doneTodos.length > 0 ? (
    +{doneTodos.length} completed todos
      {doneTodos.map(todoItem)}
    ) : ''}
    ) }