@@ -1,6 +1,6 @@
|
|||||||
import { Box, Button, Flex, IconButton } from "@radix-ui/themes"
|
import { Box, Button, Flex, IconButton } from "@radix-ui/themes"
|
||||||
import { GetRandomValues, makeUuid4 } from "@typed/id"
|
import { GetRandomValues, makeUuid4 } from "@typed/id"
|
||||||
import { Chunk, Effect, Match, Option, Ref, Runtime, Schema, Stream } from "effect"
|
import { Chunk, type DateTime, Effect, Match, Option, Ref, Schema, Stream } from "effect"
|
||||||
import { Component, Form, Subscribable } from "effect-fc"
|
import { Component, Form, Subscribable } from "effect-fc"
|
||||||
import { FaArrowDown, FaArrowUp } from "react-icons/fa"
|
import { FaArrowDown, FaArrowUp } from "react-icons/fa"
|
||||||
import { FaDeleteLeft } from "react-icons/fa6"
|
import { FaDeleteLeft } from "react-icons/fa6"
|
||||||
@@ -31,7 +31,6 @@ export type TodoProps = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
export class Todo extends Component.makeUntraced("Todo")(function*(props: TodoProps) {
|
export class Todo extends Component.makeUntraced("Todo")(function*(props: TodoProps) {
|
||||||
const runtime = yield* Effect.runtime()
|
|
||||||
const state = yield* TodosState
|
const state = yield* TodosState
|
||||||
|
|
||||||
const [
|
const [
|
||||||
@@ -83,7 +82,9 @@ export class Todo extends Component.makeUntraced("Todo")(function*(props: TodoPr
|
|||||||
state.sizeSubscribable,
|
state.sizeSubscribable,
|
||||||
form.canSubmitSubscribable,
|
form.canSubmitSubscribable,
|
||||||
])
|
])
|
||||||
const submit = yield* Form.useSubmit(form)
|
|
||||||
|
const runSync = yield* Component.useRunSync()
|
||||||
|
const runPromise = yield* Component.useRunPromise<DateTime.CurrentTimeZone>()
|
||||||
const TextFieldFormInputFC = yield* TextFieldFormInput
|
const TextFieldFormInputFC = yield* TextFieldFormInput
|
||||||
|
|
||||||
|
|
||||||
@@ -102,7 +103,7 @@ export class Todo extends Component.makeUntraced("Todo")(function*(props: TodoPr
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
{props._tag === "new" &&
|
{props._tag === "new" &&
|
||||||
<Button disabled={!canSubmit} onClick={() => submit()}>
|
<Button disabled={!canSubmit} onClick={() => void runPromise(Form.submit(form))}>
|
||||||
Add
|
Add
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
@@ -114,19 +115,19 @@ export class Todo extends Component.makeUntraced("Todo")(function*(props: TodoPr
|
|||||||
<Flex direction="column" justify="center" align="center" gap="1">
|
<Flex direction="column" justify="center" align="center" gap="1">
|
||||||
<IconButton
|
<IconButton
|
||||||
disabled={index <= 0}
|
disabled={index <= 0}
|
||||||
onClick={() => Runtime.runSync(runtime)(state.moveLeft(props.id))}
|
onClick={() => runSync(state.moveLeft(props.id))}
|
||||||
>
|
>
|
||||||
<FaArrowUp />
|
<FaArrowUp />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
||||||
<IconButton
|
<IconButton
|
||||||
disabled={index >= size - 1}
|
disabled={index >= size - 1}
|
||||||
onClick={() => Runtime.runSync(runtime)(state.moveRight(props.id))}
|
onClick={() => runSync(state.moveRight(props.id))}
|
||||||
>
|
>
|
||||||
<FaArrowDown />
|
<FaArrowDown />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
||||||
<IconButton onClick={() => Runtime.runSync(runtime)(state.remove(props.id))}>
|
<IconButton onClick={() => runSync(state.remove(props.id))}>
|
||||||
<FaDeleteLeft />
|
<FaDeleteLeft />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|||||||
Reference in New Issue
Block a user