-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added type-safe react-query setup
- Loading branch information
1 parent
9f53beb
commit cbe798e
Showing
10 changed files
with
125 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
VITE_API_BASE_URL=http://localhost:8090/api/v1 | ||
VITE_API_BASE_URL=http://localhost:8080/api/v1 |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
frontend/src/components/features/connections/ConnectionsView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Connection } from "@/types/Connection"; | ||
|
||
export default function ConnectionsView({ | ||
connections, | ||
}: { | ||
connections: Connection[]; | ||
}) { | ||
return <h1>View {connections.at(0)?.id}</h1>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { ConnectionService } from "@/services/ConnectionService"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
export const useConnectionsQuery = () => { | ||
return useQuery({ | ||
queryKey: ["connections"], | ||
queryFn: ConnectionService.findAll, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,31 @@ | ||
import ConnectionsView from "@/components/features/connections/ConnectionsView"; | ||
import { useConnectionsQuery } from "@/hooks/features/connections/useConnections"; | ||
|
||
export default function Connections() { | ||
return ( | ||
<> | ||
<div>Connections</div> | ||
</> | ||
); | ||
const connectionsQuery = useConnectionsQuery(); | ||
|
||
if (connectionsQuery.isLoading) { | ||
return ( | ||
<> | ||
<div className="flex flex-col items-center justify-between h-full"> | ||
<h1>Loading...</h1> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
if (connectionsQuery.isError) { | ||
console.log(connectionsQuery.error); | ||
throw new Error("We were not able to fetch connections."); | ||
} | ||
|
||
if (connectionsQuery.isSuccess) { | ||
return ( | ||
<> | ||
<div className="flex flex-col items-center justify-between h-full"> | ||
<ConnectionsView connections={connectionsQuery.data} /> | ||
</div> | ||
</> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import { Connection, ConnectionSchema } from "../types/Connection"; | ||
import { http } from "./kySetup"; | ||
import { z } from "zod"; | ||
import { kyInstance } from "./ky.setup"; | ||
import { ConnectionSchema } from "@/types/Connection"; | ||
|
||
const ROUTES = { | ||
FIND_ALL: "/connections", | ||
FIND_ALL: "connections", | ||
}; | ||
|
||
export const ConnectionService = { | ||
async getAllConnections() { | ||
const data = await http.get<Connection[]>(ROUTES.FIND_ALL).json(); | ||
findAll: async () => { | ||
const data = await kyInstance.get(ROUTES.FIND_ALL).json(); | ||
return z.array(ConnectionSchema).parse(data); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters