Projekt

Obecné

Profil

Stáhnout (6.77 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
            /*
21
            NEXT ITEM switching
22
            
23
            <HStack h="16" >
24
                <HStack width="50%">
25
                    <Button variant="ghost" size="lg" marginLeft={0}
26
                        onPress={onBackPressed}
27
                        leftIcon={<ChevronLeftIcon size="lg" />}>
28
                        Back
29
                    </Button>
30
                </HStack>
31
                <HStack width="50%">
32
                    <HStack width="50%">
33

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

    
97
                                    </Pressable>
98
                                );
99
                            })}
100
                            {concordances && concordances.length == 1 &&
101
                                <Pressable onPress={() => { onIndexChange(0) }}>
102
                                    <VStack alignItems={"center"} justifyContent={"center"} width={32} style={{height: 43}}>
103
                                        <HStack alignItems={"center"} mt={0 == 0 ? 1.5 : -1.5}>
104
                                            {concordances?.[0]?.cert && <CircleIcon
105
                                                size="2"
106
                                                color={CertaintyWithColors[concordances?.[0]?.cert ?? Certainty.Unknown].color}
107
                                            />}
108
                                            <Text marginLeft={2} color={0 == 0 ? "#654B07" : "#8F6A0A"} bold fontSize={"md"}>
109
                                                {concordances?.[0]?.id}
110
                                            </Text>
111
                                        </HStack>
112
                                        {0 == 0 && <Divider color="#654B07" borderWidth={2} borderRadius={5} width={105} mt={1.5} />}
113
                                    </VStack>
114

    
115
                                </Pressable>
116
                            }
117
                        </HStack>
118
                    }
119
                </ScrollView>
120
            </HStack>
121
        );
122
    }
123
    else {
124
        return <LoadingBox text={`Loading concordances...`}></LoadingBox>
125
    }
126
};
127

    
128
export default ItemTabBar
(1-1/3)