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