Extract port forwarding to external file

This commit is contained in:
Arnaud 2024-10-21 13:53:26 +02:00
parent 92a7dde971
commit f5de413cf2
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663
2 changed files with 7 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import { useQuery } from "@tanstack/react-query";
import { Echo } from "../utils/echo";
import { Errors } from "../utils/errors";
type PortForwardingResponse = { reachable: boolean };
@ -6,9 +7,7 @@ type PortForwardingResponse = { reachable: boolean };
export function usePortForwarding(online: boolean) {
const { data, isFetching, refetch } = useQuery({
queryFn: (): Promise<PortForwardingResponse> =>
fetch(import.meta.env.VITE_ECHO_URL + "/port/8070")
.then((res) => res.json())
.catch((e) => Errors.report(e)),
Echo.portForwarding().catch((e) => Errors.report(e)),
queryKey: ["port-forwarding"],
initialData: { reachable: false },

5
src/utils/echo.ts Normal file
View File

@ -0,0 +1,5 @@
export const Echo = {
portForwarding: () => fetch(import.meta.env.VITE_ECHO_URL + "/port/8070")
.then((res) => res.json())
}