1 |
9c55d3bb
|
Schwobik
|
import { useEffect, useState } from "react"
|
2 |
f386a4fe
|
Fantič
|
import { ScrollView, Text, VStack, useToast } from "native-base"
|
3 |
9c55d3bb
|
Schwobik
|
import { useSelector } from "react-redux"
|
4 |
|
|
import { RootState } from "../../stores/store"
|
5 |
ca53e9f1
|
Schwobik
|
import ItemPreview from "./ItemPreview"
|
6 |
e49b1f44
|
Schwobik
|
import { ItemPreviewType } from "../../types/listViewTypes"
|
7 |
|
|
import { log } from "../../logging/logger"
|
8 |
ca44ce3d
|
Schwobik
|
import ListViewInventoryGroup from "./ListViewInventoryGroup"
|
9 |
f386a4fe
|
Fantič
|
import { ErrorToast } from "../toast/ErrorToast"
|
10 |
ab632fe5
|
Michal Schwob
|
import LoadingBox from "../loading/LoadingBox"
|
11 |
e49b1f44
|
Schwobik
|
|
12 |
04928342
|
Schwobik
|
type ListViewProps = {
|
13 |
|
|
navigation: any
|
14 |
|
|
}
|
15 |
9c55d3bb
|
Schwobik
|
|
16 |
04928342
|
Schwobik
|
const ListView = (props: ListViewProps) => {
|
17 |
9c55d3bb
|
Schwobik
|
|
18 |
ca44ce3d
|
Schwobik
|
const inventories = useSelector((state: RootState) => state.listView.inventories)
|
19 |
cbf81c55
|
Schwobik
|
const numberOfResults = useSelector((state: RootState) => state.listView.numOfResults)
|
20 |
ab632fe5
|
Michal Schwob
|
const loading = useSelector((state: RootState) => state.listView.loading)
|
21 |
e49b1f44
|
Schwobik
|
|
22 |
f386a4fe
|
Fantič
|
const lastError = useSelector((state: RootState) => state.listView.lastError)
|
23 |
|
|
const toast = useToast();
|
24 |
|
|
|
25 |
|
|
useEffect(() => {
|
26 |
|
|
if (lastError) {
|
27 |
|
|
toast.closeAll()
|
28 |
|
|
toast.show({
|
29 |
|
|
render: ({
|
30 |
|
|
id
|
31 |
|
|
}) => {
|
32 |
|
|
return <ErrorToast headerText={"Error"} text={lastError} onClose={() => toast.close(id)} />;
|
33 |
|
|
},
|
34 |
|
|
duration: 3000
|
35 |
|
|
});
|
36 |
|
|
}
|
37 |
|
|
}, [lastError])
|
38 |
|
|
|
39 |
9c55d3bb
|
Schwobik
|
return (
|
40 |
e49b1f44
|
Schwobik
|
<>
|
41 |
f386a4fe
|
Fantič
|
<Text fontSize={16} fontWeight={"bold"} color={"primary.500"}>Search results{numberOfResults ? ` (${numberOfResults})` : ""}:</Text>
|
42 |
ab632fe5
|
Michal Schwob
|
{loading ? (
|
43 |
|
|
<LoadingBox text={"Loading..."} />
|
44 |
|
|
) :
|
45 |
|
|
inventories && inventories.length > 0 ?
|
46 |
1980ed09
|
Schwobik
|
(inventories.length > 1 ?
|
47 |
|
|
inventories.map((inventory) => (
|
48 |
f386a4fe
|
Fantič
|
<ListViewInventoryGroup
|
49 |
|
|
inventoryName={inventory.name}
|
50 |
|
|
inventoryLabel={inventory.label}
|
51 |
|
|
navigation={props.navigation}
|
52 |
|
|
/>
|
53 |
|
|
)
|
54 |
1980ed09
|
Schwobik
|
) : (
|
55 |
|
|
<ListViewInventoryGroup
|
56 |
f386a4fe
|
Fantič
|
inventoryName={inventories[0].name}
|
57 |
|
|
inventoryLabel={inventories[0].label}
|
58 |
|
|
navigation={props.navigation}
|
59 |
|
|
defaultOpen={true}
|
60 |
1980ed09
|
Schwobik
|
/>
|
61 |
|
|
)) : (
|
62 |
f386a4fe
|
Fantič
|
<Text alignSelf={"center"}>No results found</Text>
|
63 |
ca44ce3d
|
Schwobik
|
)
|
64 |
ab632fe5
|
Michal Schwob
|
|
65 |
1980ed09
|
Schwobik
|
}
|
66 |
e49b1f44
|
Schwobik
|
</>
|
67 |
9c55d3bb
|
Schwobik
|
)
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
export default ListView
|