Projekt

Obecné

Profil

Stáhnout (2.27 KB) Statistiky
| Větev: | Tag: | Revize:
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 e49b1f44 Schwobik
11 04928342 Schwobik
type ListViewProps = {
12
    navigation: any
13
}
14 9c55d3bb Schwobik
15 04928342 Schwobik
const ListView = (props: ListViewProps) => {
16 9c55d3bb Schwobik
17 ca44ce3d Schwobik
    const inventories = useSelector((state: RootState) => state.listView.inventories)
18 cbf81c55 Schwobik
    const numberOfResults = useSelector((state: RootState) => state.listView.numOfResults)
19 e49b1f44 Schwobik
20
21 f386a4fe Fantič
    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 9c55d3bb Schwobik
    return (
39 e49b1f44 Schwobik
        <>
40 f386a4fe Fantič
            <Text fontSize={16} fontWeight={"bold"} color={"primary.500"}>Search results{numberOfResults ? ` (${numberOfResults})` : ""}:</Text>
41
            {inventories && inventories.length > 0 ?
42 1980ed09 Schwobik
                (inventories.length > 1 ?
43
                    inventories.map((inventory) => (
44 f386a4fe Fantič
                        <ListViewInventoryGroup
45
                            inventoryName={inventory.name}
46
                            inventoryLabel={inventory.label}
47
                            navigation={props.navigation}
48
                        />
49
                    )
50 1980ed09 Schwobik
                    ) : (
51
                        <ListViewInventoryGroup
52 f386a4fe Fantič
                            inventoryName={inventories[0].name}
53
                            inventoryLabel={inventories[0].label}
54
                            navigation={props.navigation}
55
                            defaultOpen={true}
56 1980ed09 Schwobik
                        />
57
                    )) : (
58 f386a4fe Fantič
                    <Text alignSelf={"center"}>No results found</Text>
59 ca44ce3d Schwobik
                )
60 1980ed09 Schwobik
            }
61 e49b1f44 Schwobik
        </>
62 9c55d3bb Schwobik
    )
63
}
64
65
export default ListView