1 |
f386a4fe
|
Fantič
|
import { Center, Image, Pressable, ScrollView, Text, useToast } from "native-base"
|
2 |
4da7b143
|
Schwobik
|
import { useDispatch, useSelector } from "react-redux"
|
3 |
|
|
import { AppDispatch, RootState } from "../stores/store"
|
4 |
c8be2597
|
Fantič
|
import { useContext, useEffect, useState } from "react"
|
5 |
4da7b143
|
Schwobik
|
import { fetchData } from "../stores/actions/homePageThunks"
|
6 |
|
|
import { ApplicationHeading } from "../components/reusables/ApplicationHeading"
|
7 |
|
|
import LoadingBox from "../components/loading/LoadingBox"
|
8 |
|
|
import { DrawerScreenProps } from "@react-navigation/drawer"
|
9 |
|
|
import { RootDrawerParamList } from "./Navigation"
|
10 |
|
|
import { log } from "../logging/logger"
|
11 |
8c3203e0
|
Schwobik
|
import { HOME_PAGE_IMG_URL } from "../api/constants"
|
12 |
f386a4fe
|
Fantič
|
import { ErrorToast } from "../components/toast/ErrorToast"
|
13 |
4da7b143
|
Schwobik
|
// import { Image } from "react-native"
|
14 |
|
|
|
15 |
|
|
const HomePage = ({navigation}: DrawerScreenProps<RootDrawerParamList, 'Home'>) => {
|
16 |
|
|
const data = useSelector((state: RootState) => state.homePage.data)
|
17 |
|
|
const loading = useSelector((state: RootState) => state.homePage.loading)
|
18 |
f386a4fe
|
Fantič
|
const lastError = useSelector((state: RootState) => state.itemViewState.lastError)
|
19 |
|
|
const toast = useToast();
|
20 |
|
|
|
21 |
c8be2597
|
Fantič
|
useEffect(() => {
|
22 |
|
|
if (lastError) {
|
23 |
f386a4fe
|
Fantič
|
toast.closeAll()
|
24 |
|
|
toast.show({
|
25 |
|
|
render: ({
|
26 |
|
|
id
|
27 |
|
|
}) => {
|
28 |
|
|
return <ErrorToast headerText={"Error"} text={lastError} onClose={() => toast.close(id)} />;
|
29 |
|
|
},
|
30 |
|
|
duration: 3000
|
31 |
|
|
});
|
32 |
c8be2597
|
Fantič
|
}
|
33 |
|
|
}, [lastError])
|
34 |
|
|
|
35 |
4da7b143
|
Schwobik
|
const [aspectRatio, setAspectRatio] = useState(1.0)
|
36 |
|
|
|
37 |
|
|
const dispatch = useDispatch<AppDispatch>()
|
38 |
|
|
|
39 |
|
|
useEffect(() => {
|
40 |
|
|
if (data === null || data.length === 0 && !loading) {
|
41 |
|
|
dispatch(fetchData())
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
}, [])
|
45 |
b7014ba2
|
Schwobik
|
|
46 |
c8be2597
|
Fantič
|
|
47 |
|
|
|
48 |
b7014ba2
|
Schwobik
|
return (
|
49 |
4da7b143
|
Schwobik
|
<Center m={2} mb={10}>
|
50 |
|
|
{ loading ? (
|
51 |
|
|
<LoadingBox text={ "Loading..." }/>
|
52 |
|
|
) : (
|
53 |
|
|
<>
|
54 |
|
|
<ApplicationHeading/>
|
55 |
cbf81c55
|
Schwobik
|
<ScrollView mb={5} >
|
56 |
4da7b143
|
Schwobik
|
<Image
|
57 |
8c3203e0
|
Schwobik
|
source={ {uri: HOME_PAGE_IMG_URL} }
|
58 |
4da7b143
|
Schwobik
|
w={"100%"} h={ 200 }
|
59 |
|
|
resizeMode={"contain"}
|
60 |
|
|
alignSelf={ "center" }
|
61 |
|
|
alt={ "Rudolf-Aachen" }
|
62 |
|
|
/>
|
63 |
|
|
{ data && data.length > 0 && (
|
64 |
|
|
<Text
|
65 |
|
|
mx={ 2 }
|
66 |
|
|
fontSize={ "sm" }
|
67 |
|
|
lineHeight={"sm"}
|
68 |
|
|
color={"gray.500"}
|
69 |
|
|
textAlign={"justify"}
|
70 |
|
|
>
|
71 |
|
|
{data[0]["general"].text}
|
72 |
|
|
</Text>
|
73 |
|
|
)}
|
74 |
|
|
<Text
|
75 |
|
|
mt={ 2 }
|
76 |
|
|
bold
|
77 |
|
|
fontSize={"xl"}
|
78 |
|
|
color={"primary.500"}
|
79 |
|
|
>
|
80 |
|
|
Inventories
|
81 |
|
|
</Text>
|
82 |
|
|
{ data && data.length > 1 && data.slice(1).map((item) => (
|
83 |
|
|
<Pressable
|
84 |
|
|
onPress={() => navigation.navigate("Search", {inventoryId: Object.keys(item)[0]}) }
|
85 |
|
|
key={ Object.values(item)[0].label }
|
86 |
|
|
rounded={ "md" }
|
87 |
|
|
borderWidth={ 1 }
|
88 |
|
|
borderColor={ "gray.300" }
|
89 |
|
|
m = { 2 }
|
90 |
|
|
p={ 3 }
|
91 |
|
|
>
|
92 |
|
|
<Text
|
93 |
|
|
bold
|
94 |
|
|
fontSize={ "md" }
|
95 |
|
|
mb={1}
|
96 |
|
|
>
|
97 |
|
|
{ Object.values(item)[0].label }
|
98 |
|
|
</Text>
|
99 |
|
|
<Text
|
100 |
|
|
fontSize={ "sm" }
|
101 |
|
|
lineHeight={"sm"}
|
102 |
|
|
color={"gray.500"}
|
103 |
|
|
textAlign={"justify"}
|
104 |
|
|
>
|
105 |
|
|
{ Object.values(item)[0].text }
|
106 |
|
|
</Text>
|
107 |
|
|
</Pressable>
|
108 |
|
|
)) }
|
109 |
|
|
|
110 |
|
|
</ScrollView>
|
111 |
|
|
</>
|
112 |
|
|
) }
|
113 |
b7014ba2
|
Schwobik
|
</Center>
|
114 |
|
|
)
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
export default HomePage
|