import * as Domain from "@/domain" import { Box, Button, Flex, IconButton, TextArea } from "@radix-ui/themes" import { GetRandomValues, makeUuid4 } from "@typed/id" import { Chunk, Effect, Match, Option, Ref, Runtime, SubscriptionRef } from "effect" import { Component, Hook, Memoized } from "effect-fc" import { SubscriptionSubRef } from "effect-fc/types" import { FaArrowDown, FaArrowUp } from "react-icons/fa" import { FaDeleteLeft } from "react-icons/fa6" import { TodosState } from "./TodosState.service" const makeTodo = makeUuid4.pipe( Effect.map(id => Domain.Todo.Todo.make({ id, content: "", completedAt: Option.none(), })), Effect.provide(GetRandomValues.CryptoRandom), ) export type TodoProps = ( | { readonly _tag: "new", readonly index?: never } | { readonly _tag: "edit", readonly index: number } ) export class Todo extends Component.make(function* Todo(props: TodoProps) { const runtime = yield* Effect.runtime() const state = yield* TodosState const [ref, contentRef] = yield* Hook.useMemo(() => Match.value(props).pipe( Match.tag("new", () => Effect.andThen(makeTodo, SubscriptionRef.make)), Match.tag("edit", ({ index }) => Effect.succeed(SubscriptionSubRef.makeFromChunkRef(state.ref, index))), Match.exhaustive, Effect.map(ref => [ ref, SubscriptionSubRef.makeFromPath(ref, ["content"]), ] as const), ), [props._tag, props.index]) const [content, size] = yield* Hook.useSubscribeRefs(contentRef, state.sizeRef) return (