Working mutation progress
All checks were successful
Lint / lint (push) Successful in 13s

This commit is contained in:
Julien Valverdé
2025-03-21 02:14:36 +01:00
parent 8c0d6b4c8a
commit aab83907ba
2 changed files with 26 additions and 15 deletions

View File

@@ -16,14 +16,19 @@ export const Route = createFileRoute("/query/usemutation")({
const Result = Schema.Array(Schema.String)
function RouteComponent() {
const runSync = R.useRunSync()
const runFork = R.useRunFork()
const [count, setCount] = useState(1)
const mutation = R.useMutation({
mutation: ([count]: readonly [count: number]) => Console.log(`Querying ${ count } IDs...`).pipe(
Effect.andThen(QueryProgress.QueryProgress.update(() =>
AsyncData.Progress.make({ loaded: 0, total: Option.some(100) })
)),
Effect.andThen(Effect.sleep("500 millis")),
Effect.tap(() => QueryProgress.QueryProgress.get),
Effect.tap(() => QueryProgress.QueryProgress.update(() =>
AsyncData.Progress.make({ loaded: 50, total: Option.some(100) })
)),
Effect.andThen(HttpClient.get(`https://www.uuidtools.com/api/generate/v4/count/${ count }`)),
HttpClient.withTracerPropagation(false),
Effect.flatMap(res => res.json),
@@ -63,8 +68,7 @@ function RouteComponent() {
<Button onClick={() => mutation.forkMutate(count).pipe(
Effect.flatMap(([, state]) => Stream.runForEach(state, Console.log)),
Effect.andThen(Console.log("Mutation done.")),
Effect.forkDaemon,
runSync,
runFork,
)}>
Get
</Button>