@@ -3,6 +3,8 @@ import { Definition } from "../../../interfaces/Data";
3
3
import dummyEntries from "../../../assets/data/entries" ;
4
4
import { twMerge } from "tailwind-merge" ;
5
5
import MaterialIcon from "../../../common/MaterialIcon" ;
6
+ import api from "../../../helpers/api" ;
7
+ import axios from "axios" ;
6
8
7
9
interface ListViewProps {
8
10
schema : Definition ;
@@ -14,7 +16,23 @@ export default function ListView(props: ListViewProps) {
14
16
15
17
const [ visibility , setVisibility ] = useState < object > ( { } ) ;
16
18
17
- const content = dummyEntries ;
19
+ const exposedApiBase = import . meta. env . VITE_PUBLIC_ENDPOINT_BASE ;
20
+
21
+ // const content = dummyEntries;
22
+ const [ content , setContent ] = useState < Array < any > > ( ) ;
23
+
24
+ async function loadData ( ) {
25
+ const uri = await api . getCollectionEndpoint ( props . collectionId ) ;
26
+ const cnt = await axios . get < { id : number ; data : object } [ ] > (
27
+ `http://${ exposedApiBase } /d/${ uri } ` . replace ( "localhost" , "127.0.0.1" )
28
+ ) ;
29
+
30
+ setContent ( cnt . data . map ( ( d ) => d . data ) ) ;
31
+ }
32
+
33
+ useEffect ( ( ) => {
34
+ loadData ( ) ;
35
+ } , [ ] ) ;
18
36
19
37
return (
20
38
< div className = "flex flex-col" >
@@ -41,40 +59,41 @@ export default function ListView(props: ListViewProps) {
41
59
</ label >
42
60
) ) }
43
61
</ div >
44
-
45
- < table className = "flex-1 mt-10" >
46
- < thead >
47
- < tr >
48
- { Object . keys ( content [ 0 ] ) . map ( ( item , key ) =>
49
- visibility [ item as keyof typeof visibility ] ? (
50
- < th className = "border h-16 font-medium" key = { key } >
51
- { item }
52
- </ th >
53
- ) : null
54
- ) }
55
- </ tr >
56
- </ thead >
57
- < tbody >
58
- { content . map ( ( val , key ) => {
59
- return (
60
- < tr
61
- key = { key }
62
- className = "relative h-10 hover:bg-secondary hover:bg-opacity-30 cursor-pointer"
63
- >
64
- { Object . keys ( content [ 0 ] ) . map ( ( item , key ) =>
65
- visibility [ item as keyof typeof visibility ] ? (
66
- < td className = "border pl-2" key = { key } >
67
- { JSON . stringify ( val [ item as keyof typeof val ] ) }
68
- </ td >
69
- ) : (
70
- < > </ >
71
- )
72
- ) }
73
- </ tr >
74
- ) ;
75
- } ) }
76
- </ tbody >
77
- </ table >
62
+ { content && (
63
+ < table className = "flex-1 mt-10" >
64
+ < thead >
65
+ < tr >
66
+ { Object . keys ( content [ 0 ] ) . map ( ( item , key ) =>
67
+ visibility [ item as keyof typeof visibility ] ? (
68
+ < th className = "border h-16 font-medium" key = { key } >
69
+ { item }
70
+ </ th >
71
+ ) : null
72
+ ) }
73
+ </ tr >
74
+ </ thead >
75
+ < tbody >
76
+ { content . map ( ( val , key ) => {
77
+ return (
78
+ < tr
79
+ key = { key }
80
+ className = "relative h-10 hover:bg-secondary hover:bg-opacity-30 cursor-pointer"
81
+ >
82
+ { Object . keys ( content [ 0 ] ) . map ( ( item , key ) =>
83
+ visibility [ item as keyof typeof visibility ] ? (
84
+ < td className = "border pl-2" key = { key } >
85
+ { JSON . stringify ( val [ item as keyof typeof val ] ) }
86
+ </ td >
87
+ ) : (
88
+ < > </ >
89
+ )
90
+ ) }
91
+ </ tr >
92
+ ) ;
93
+ } ) }
94
+ </ tbody >
95
+ </ table >
96
+ ) }
78
97
</ div >
79
98
) ;
80
99
}
0 commit comments