Projekt

Obecné

Profil

Stáhnout (2.48 KB) Statistiky
| Větev: | Tag: | Revize:
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
import LoadingBox from "../loading/LoadingBox"
11

    
12
type ListViewProps = {
13
    navigation: any
14
}
15

    
16
const ListView = (props: ListViewProps) => {
17

    
18
    const inventories = useSelector((state: RootState) => state.listView.inventories)
19
    const numberOfResults = useSelector((state: RootState) => state.listView.numOfResults)
20
    const loading = useSelector((state: RootState) => state.listView.loading)
21

    
22
    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
    return (
40
        <>
41
            <Text fontSize={16} fontWeight={"bold"} color={"primary.500"}>Search results{numberOfResults ? ` (${numberOfResults})` : ""}:</Text>
42
            {loading ? (
43
                <LoadingBox text={"Loading..."} />
44
            )  :
45
            inventories && inventories.length > 0 ?
46
                (inventories.length > 1 ?
47
                    inventories.map((inventory) => (
48
                        <ListViewInventoryGroup
49
                            inventoryName={inventory.name}
50
                            inventoryLabel={inventory.label}
51
                            navigation={props.navigation}
52
                        />
53
                    )
54
                    ) : (
55
                        <ListViewInventoryGroup
56
                            inventoryName={inventories[0].name}
57
                            inventoryLabel={inventories[0].label}
58
                            navigation={props.navigation}
59
                            defaultOpen={true}
60
                        />
61
                    )) : (
62
                    <Text alignSelf={"center"}>No results found</Text>
63
                )
64

    
65
            }
66
        </>
67
    )
68
}
69

    
70
export default ListView
(3-3/4)