Skip to content

Commit 8375ee9

Browse files
committed
Only suspend the table body
1 parent f19f34b commit 8375ee9

File tree

1 file changed

+51
-27
lines changed

1 file changed

+51
-27
lines changed

frontend/src/routes/_layout/items.tsx

+51-27
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,30 @@ export const Route = createFileRoute("/_layout/items")({
2424
component: Items,
2525
})
2626

27-
function ItemsTable() {
27+
function ItemsTableBody() {
2828
const { data: items } = useSuspenseQuery({
2929
queryKey: ["items"],
3030
queryFn: () => ItemsService.readItems({}),
3131
})
32+
33+
return (
34+
<Tbody>
35+
{items.data.map((item) => (
36+
<Tr key={item.id}>
37+
<Td>{item.id}</Td>
38+
<Td>{item.title}</Td>
39+
<Td color={!item.description ? "ui.dim" : "inherit"}>
40+
{item.description || "N/A"}
41+
</Td>
42+
<Td>
43+
<ActionsMenu type={"Item"} value={item} />
44+
</Td>
45+
</Tr>
46+
))}
47+
</Tbody>
48+
)
49+
}
50+
function ItemsTable() {
3251
return (
3352
<TableContainer>
3453
<Table size={{ base: "sm", md: "md" }}>
@@ -40,20 +59,35 @@ function ItemsTable() {
4059
<Th>Actions</Th>
4160
</Tr>
4261
</Thead>
43-
<Tbody>
44-
{items.data.map((item) => (
45-
<Tr key={item.id}>
46-
<Td>{item.id}</Td>
47-
<Td>{item.title}</Td>
48-
<Td color={!item.description ? "ui.dim" : "inherit"}>
49-
{item.description || "N/A"}
50-
</Td>
51-
<Td>
52-
<ActionsMenu type={"Item"} value={item} />
53-
</Td>
54-
</Tr>
55-
))}
56-
</Tbody>
62+
<ErrorBoundary
63+
fallbackRender={({ error }) => (
64+
<Tbody>
65+
<Tr>
66+
<Td colSpan={4}>Something went wrong: {error.message}</Td>
67+
</Tr>
68+
</Tbody>
69+
)}
70+
>
71+
<Suspense
72+
fallback={
73+
<Tbody>
74+
{new Array(5).fill(null).map((_, index) => (
75+
<Tr key={index}>
76+
{new Array(4).fill(null).map((_, index) => (
77+
<Td key={index}>
78+
<Flex>
79+
<Skeleton height="20px" width="20px" />
80+
</Flex>
81+
</Td>
82+
))}
83+
</Tr>
84+
))}
85+
</Tbody>
86+
}
87+
>
88+
<ItemsTableBody />
89+
</Suspense>
90+
</ErrorBoundary>
5791
</Table>
5892
</TableContainer>
5993
)
@@ -66,18 +100,8 @@ function Items() {
66100
Items Management
67101
</Heading>
68102

69-
<ErrorBoundary fallback={<div>Something went wrong</div>}>
70-
<Suspense
71-
fallback={
72-
<Flex py={8} gap={4}>
73-
<Skeleton height="40px" width={100} />
74-
</Flex>
75-
}
76-
>
77-
<Navbar type={"Item"} />
78-
<ItemsTable />
79-
</Suspense>
80-
</ErrorBoundary>
103+
<Navbar type={"Item"} />
104+
<ItemsTable />
81105
</Container>
82106
)
83107
}

0 commit comments

Comments
 (0)