This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { HttpClientError } from "@effect/platform"
|
import { HttpClientError } from "@effect/platform"
|
||||||
import { AlertDialog, Button, Flex, Text } from "@radix-ui/themes"
|
import { AlertDialog, Button, Flex, Text } from "@radix-ui/themes"
|
||||||
import { ErrorHandler } from "@reffuse/extension-query"
|
import { ErrorHandler } from "@reffuse/extension-query"
|
||||||
import { Cause, Chunk, Context, Effect, Match, Option, Queue, Stream } from "effect"
|
import { Cause, Chunk, Context, Effect, Match, Option, Stream } from "effect"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { R } from "./reffuse"
|
import { R } from "./reffuse"
|
||||||
|
|
||||||
@@ -14,36 +14,19 @@ export const QueryErrorHandlerLive = ErrorHandler.layer(QueryErrorHandler)
|
|||||||
|
|
||||||
|
|
||||||
export function VQueryErrorHandler() {
|
export function VQueryErrorHandler() {
|
||||||
const queue = R.useMemo(() => Queue.unbounded<Cause.Cause<
|
const [failure, setFailure] = useState(Option.none<Cause.Cause<
|
||||||
ErrorHandler.Error<Context.Tag.Service<QueryErrorHandler>>
|
ErrorHandler.Error<Context.Tag.Service<QueryErrorHandler>>
|
||||||
>>(), [])
|
>>())
|
||||||
|
|
||||||
R.useFork(() => QueryErrorHandler.pipe(Effect.flatMap(handler =>
|
R.useFork(() => QueryErrorHandler.pipe(Effect.flatMap(handler =>
|
||||||
Stream.runForEach(handler.errors, v => Queue.offer(queue, v))
|
Stream.runForEach(handler.errors, v => Effect.sync(() =>
|
||||||
)), [queue])
|
setFailure(Option.some(v))
|
||||||
|
))
|
||||||
const [failure, setFailure] = useState(R.useMemo(() => Queue.poll(queue), []))
|
)), [])
|
||||||
|
|
||||||
const next = R.useCallbackSync(() => Queue.poll(queue).pipe(
|
|
||||||
Effect.map(setFailure)
|
|
||||||
), [queue])
|
|
||||||
|
|
||||||
// R.useFork(() => QueryErrorHandler.pipe(Effect.flatMap(handler =>
|
|
||||||
// Stream.runForEach(handler.errors, flow(
|
|
||||||
// Cause.failures,
|
|
||||||
// Chunk.map(flow(Match.value,
|
|
||||||
// Match.tag("RequestError", () => Effect.sync(() => {})),
|
|
||||||
// Match.tag("ResponseError", () => Effect.sync(() => {})),
|
|
||||||
// Match.exhaustive,
|
|
||||||
// )),
|
|
||||||
// Effect.all,
|
|
||||||
// ))
|
|
||||||
// )), [])
|
|
||||||
|
|
||||||
|
|
||||||
return Option.match(failure, {
|
return Option.match(failure, {
|
||||||
onSome: v => (
|
onSome: v => (
|
||||||
<AlertDialog.Root>
|
<AlertDialog.Root open>
|
||||||
<AlertDialog.Content maxWidth="450px">
|
<AlertDialog.Content maxWidth="450px">
|
||||||
<AlertDialog.Title>Error</AlertDialog.Title>
|
<AlertDialog.Title>Error</AlertDialog.Title>
|
||||||
<AlertDialog.Description size="2">
|
<AlertDialog.Description size="2">
|
||||||
@@ -59,9 +42,11 @@ export function VQueryErrorHandler() {
|
|||||||
</AlertDialog.Description>
|
</AlertDialog.Description>
|
||||||
|
|
||||||
<Flex gap="3" mt="4" justify="end">
|
<Flex gap="3" mt="4" justify="end">
|
||||||
<Button variant="solid" color="red" onClick={next}>
|
<AlertDialog.Action>
|
||||||
Ok
|
<Button variant="solid" color="red" onClick={() => setFailure(Option.none())}>
|
||||||
</Button>
|
Ok
|
||||||
|
</Button>
|
||||||
|
</AlertDialog.Action>
|
||||||
</Flex>
|
</Flex>
|
||||||
</AlertDialog.Content>
|
</AlertDialog.Content>
|
||||||
</AlertDialog.Root>
|
</AlertDialog.Root>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { Layer } from "effect"
|
|||||||
import { StrictMode } from "react"
|
import { StrictMode } from "react"
|
||||||
import { createRoot } from "react-dom/client"
|
import { createRoot } from "react-dom/client"
|
||||||
import { ReffuseRuntime } from "reffuse"
|
import { ReffuseRuntime } from "reffuse"
|
||||||
import { QueryErrorHandler, QueryErrorHandlerLive, VQueryErrorHandler } from "./QueryErrorHandler"
|
import { QueryErrorHandler, QueryErrorHandlerLive } from "./QueryErrorHandler"
|
||||||
import { GlobalContext } from "./reffuse"
|
import { GlobalContext } from "./reffuse"
|
||||||
import { routeTree } from "./routeTree.gen"
|
import { routeTree } from "./routeTree.gen"
|
||||||
|
|
||||||
@@ -33,7 +33,6 @@ createRoot(document.getElementById("root")!).render(
|
|||||||
<StrictMode>
|
<StrictMode>
|
||||||
<ReffuseRuntime.Provider>
|
<ReffuseRuntime.Provider>
|
||||||
<GlobalContext.Provider layer={layer}>
|
<GlobalContext.Provider layer={layer}>
|
||||||
<VQueryErrorHandler />
|
|
||||||
<RouterProvider router={router} />
|
<RouterProvider router={router} />
|
||||||
</GlobalContext.Provider>
|
</GlobalContext.Provider>
|
||||||
</ReffuseRuntime.Provider>
|
</ReffuseRuntime.Provider>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { VQueryErrorHandler } from "@/QueryErrorHandler"
|
||||||
import { Container, Flex, Theme } from "@radix-ui/themes"
|
import { Container, Flex, Theme } from "@radix-ui/themes"
|
||||||
import { createRootRoute, Link, Outlet } from "@tanstack/react-router"
|
import { createRootRoute, Link, Outlet } from "@tanstack/react-router"
|
||||||
import { TanStackRouterDevtools } from "@tanstack/router-devtools"
|
import { TanStackRouterDevtools } from "@tanstack/router-devtools"
|
||||||
@@ -26,6 +27,8 @@ function Root() {
|
|||||||
</Container>
|
</Container>
|
||||||
|
|
||||||
<Outlet />
|
<Outlet />
|
||||||
|
|
||||||
|
<VQueryErrorHandler />
|
||||||
<TanStackRouterDevtools />
|
<TanStackRouterDevtools />
|
||||||
</Theme>
|
</Theme>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user