@@ -24,11 +24,30 @@ export const Route = createFileRoute("/_layout/items")({
24
24
component : Items ,
25
25
} )
26
26
27
- function ItemsTable ( ) {
27
+ function ItemsTableBody ( ) {
28
28
const { data : items } = useSuspenseQuery ( {
29
29
queryKey : [ "items" ] ,
30
30
queryFn : ( ) => ItemsService . readItems ( { } ) ,
31
31
} )
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 ( ) {
32
51
return (
33
52
< TableContainer >
34
53
< Table size = { { base : "sm" , md : "md" } } >
@@ -40,20 +59,35 @@ function ItemsTable() {
40
59
< Th > Actions</ Th >
41
60
</ Tr >
42
61
</ 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 >
57
91
</ Table >
58
92
</ TableContainer >
59
93
)
@@ -66,18 +100,8 @@ function Items() {
66
100
Items Management
67
101
</ Heading >
68
102
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 />
81
105
</ Container >
82
106
)
83
107
}
0 commit comments