progress?

This commit is contained in:
2025-01-15 11:31:29 -06:00
parent f1921dc115
commit d1e5f7c61c
4 changed files with 143 additions and 3 deletions
+5 -2
View File
@@ -1,12 +1,14 @@
import { Routes, Route} from 'react-router';
import Home from './pages/home.tsx';
import Inventory from "./pages/inventory.tsx";
import { QueryClientProvider, QueryClient } from '@tanstack/react-query';
// Create a client
const queryClient = new QueryClient()
function App() {
return (
<QueryClientProvider client={queryClient}>
<>
<Routes>
<Route index element={<Home />} />
@@ -15,6 +17,7 @@ function App() {
</>
</QueryClientProvider>
)
}
+37 -1
View File
@@ -1,8 +1,24 @@
import {useQuery} from "@tanstack/react-query";
import {Link} from "react-router";
import inventory from "./inventory.tsx";
import { Key, ReactElement, JSXElementConstructor, ReactNode, ReactPortal } from "react";
function Inventory() {
const {isPending, error, data, isFetching} = useQuery({
queryKey: ['inventory'],
queryFn: async () => {
const response = await fetch(
'https://barkdev.ts.drewr.io/inventory',
)
return await response.json()
},
})
if (isPending) return 'Loading...'
if (error) return 'An error has occurred: ' + error.message
return (
<>
@@ -15,7 +31,27 @@ function Inventory() {
<Link to="/">
<button className="bg-brand rounded text-white font-bold px-4 py-2">Home</button>
</Link>
<div>{isFetching ? 'Updating...' : ''}</div>
<table className="w-1/2">
<thead>
<tr className="text-left">
<th className="text-brand">ID</th>
<th className="text-brand">Brand</th>
<th className="text-brand">Item</th>
<th className="text-brand">Status</th>
</tr>
</thead>
<tbody>
{data.map((data: { id: Key | null | undefined; brand: string | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | null | undefined; name: string | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | null | undefined; status: string | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | null | undefined; }) => (
<tr key={data.id}>
<td>{data.brand}</td>
<td>{data.name}</td>
<td>{data.status}</td>
</tr>
))}
</tbody>
</table>
</>
)
}