/
grid.tsx
89 lines (84 loc) · 2.45 KB
/
grid.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import React from 'react';
import {
IonCard,
IonCardContent,
IonRow,
IonCol,
IonSpinner
} from '@ionic/react';
import Card from './card';
import AppContext from '../AppContext';
const Grid: React.FC<{ pageKey: string }> = (props) => {
const pageKey = props.pageKey;
const [value, loading, error] = Object.values(React.useContext(AppContext));
return (
<React.Fragment>
{error && (
<IonRow>
<IonCol>
<IonCard color="light">
<IonCardContent>Error: {JSON.stringify(error)}</IonCardContent>
</IonCard>
</IonCol>
</IonRow>
)}
{loading && (
<IonRow>
<IonCol>
<IonCard color="light">
<IonCardContent class="ion-text-center">
<IonSpinner />
</IonCardContent>
</IonCard>
</IonCol>
</IonRow>
)}
{value && !(pageKey in value) && (
<IonRow>
<IonCol>
<IonCard color="light">
<IonCardContent class="ion-text-center">
Content unavailable. If the issue persists contact the event team.
</IonCardContent>
</IonCard>
</IonCol>
</IonRow>
)}
{value && pageKey in value && (
<React.Fragment>
{Object.keys(value[pageKey])
.sort((a, b) => parseInt(a) - parseInt(b))
.map((key) => {
const item = value[pageKey][key];
if (!item['0']) {
// item is one leveled (0 and 1 are column positions)
return (
<IonRow key={key}>
<IonCol>
<Card {...item} />
</IonCol>
</IonRow>
);
} else {
// item is 2 cards for the row
// 0 is left 1 is right
item['0']['smallTitle'] = true;
item['1']['smallTitle'] = true;
return (
<IonRow key={key}>
<IonCol>
<Card {...item['0']} />
</IonCol>
<IonCol>
<Card {...item['1']} />
</IonCol>
</IonRow>
);
}
})}
</React.Fragment>
)}
</React.Fragment>
);
};
export default Grid;