Projekt

Obecné

Profil

Stáhnout (6.61 KB) Statistiky
| Větev: | Tag: | Revize:
1
import { HStack, CircleIcon, View, ScrollView, Button, Center, Heading, Pressable, Text, Box, Container, VStack, Icon, ArrowBackIcon, ChevronLeftIcon, ChevronRightIcon, useToast, Divider } from "native-base";
2
import { CertaintyWithColors } from "../../stores/reducers/itemSlice";
3
import { Certainty, Concordance } from "../../types/item";
4
import LoadingBox from "../loading/LoadingBox";
5
import { DrawerNavigationProp } from "@react-navigation/drawer";
6
import { RootStackParamList } from "../../pages/Navigation";
7
import { InfoToast } from "../toast/InfoToast";
8

    
9
// custom render Tab
10
const ItemTabBar = (props: { navigationState: { routes: any[] }, concordances: Concordance[], index: number, onIndexChange: any, onBackPressed: any, navigation: DrawerNavigationProp<RootStackParamList, "Item", undefined>, nextItem?: string | boolean, prevItem?: string | boolean }) => {
11

    
12
    const { concordances, onIndexChange, index, onBackPressed, nextItem, prevItem } = props
13

    
14
    const toast = useToast();
15

    
16
    console.log(concordances)
17

    
18
    if (concordances && concordances.length > 0) {
19
        return (
20
            <VStack>
21
                {/* <HStack h="16" >
22
                    <HStack width="50%">
23
                        <Button variant="ghost" size="lg" marginLeft={0}
24
                            onPress={onBackPressed}
25
                            leftIcon={<ChevronLeftIcon size="lg" />}>
26
                            Back
27
                        </Button>
28
                    </HStack>
29
                    <HStack width="50%">
30
                        <HStack width="50%">
31

    
32
                        </HStack>
33
                        <HStack marginRight={0}>
34
                            <Button variant="ghost" size="lg"
35
                                onPress={() => {
36
                                    if(prevItem){
37
                                        console.log(prevItem)
38
                                        props.navigation.navigate("Item", { itemId: prevItem.toString() })
39
                                    }
40
                                    else{
41
                                        toast.show({
42
                                            render: ({
43
                                                id
44
                                            }) => {
45
                                                return <InfoToast text={"No previous item..."} onClose={() => toast.close(id)} />;
46
                                            },
47
                                            duration: 3000
48
                                        });
49
                                    }
50
                                }}
51
                                leftIcon={<ChevronLeftIcon size="lg" />}>
52
                            </Button>
53
                            <Button variant="ghost" size="lg"
54
                                onPress={() => {
55
                                    
56
                                    if(nextItem){
57
                                        props.navigation.navigate("Item", { itemId: nextItem.toString() })
58
                                    }
59
                                    else{
60
                                        toast.show({
61
                                            render: ({
62
                                                id
63
                                            }) => {
64
                                                return <InfoToast text={"No next item..."} onClose={() => toast.close(id)} />;
65
                                            },
66
                                            duration: 3000
67
                                        });
68
                                    }
69
                                }}
70
                                leftIcon={<ChevronRightIcon size="lg" />}>
71
                            </Button>
72
                        </HStack>
73
                    </HStack>
74
                </HStack> */}
75
                <View height={16} backgroundColor={"#F5F4F1"}>
76
                    <ScrollView contentContainerStyle={{ flexGrow: 1 }} flex="1" horizontal={true}>
77
                        {props.navigationState.routes.length > 1 ? (
78
                            <HStack borderBottomWidth={1} flex="1" borderColor="light.400">
79
                                {props.navigationState.routes.map((route, i) => {
80
                                    return (
81
                                        <Pressable onPress={() => { onIndexChange(i) }} width="100%">
82
                                        <VStack alignItems={"center"} >
83
                                            <HStack alignItems={"center"} width={32}>
84
                                                <CircleIcon
85
                                                    size="2"
86
                                                    color={CertaintyWithColors[concordances[i]?.cert ?? Certainty.Unknown].color}
87
                                                />
88
                                                <Text marginLeft={1}>
89
                                                    <Text bold>{concordances[i]?.id}</Text>
90
                                                </Text>
91
                                            </HStack>
92
                                            {i == index && <Divider color="primary" borderWidth={1} width={30} mt={2} />}
93
                                        </VStack>
94
        
95
                                    </Pressable>
96
                                    );
97
                                })}
98
                            </HStack>
99
                        ) : (
100
                            // One item only
101

    
102

    
103
                            <Pressable onPress={() => { onIndexChange(0) }} width="100%">
104
                                <VStack alignItems={"center"} >
105
                                    <HStack alignItems={"center"} width="100%">
106
                                        <CircleIcon
107
                                            size="2"
108
                                            color={CertaintyWithColors[concordances[0]?.cert ?? Certainty.Unknown].color}
109
                                        />
110
                                        <Text marginLeft={1}>
111
                                            <Text bold>{concordances[0]?.id}</Text>
112
                                        </Text>
113
                                    </HStack>
114
                                    <Divider color="primary" borderWidth={1} width={30} mt={2} />
115
                                </VStack>
116

    
117
                            </Pressable>
118
                        )}
119
                    </ScrollView>
120
                </View>
121
            </VStack>
122

    
123
        );
124
    }
125
    else {
126
        return <LoadingBox text={`Loading concordances...`}></LoadingBox>
127
    }
128
};
129

    
130
export default ItemTabBar
(1-1/2)