Projekt

Obecné

Profil

Stáhnout (6.61 KB) Statistiky
| Větev: | Tag: | Revize:
1 f4af30c8 Fantič
import { HStack, CircleIcon, View, ScrollView, Button, Center, Heading, Pressable, Text, Box, Container, VStack, Icon, ArrowBackIcon, ChevronLeftIcon, ChevronRightIcon, useToast, Divider } from "native-base";
2 d281786c Fantič
import { CertaintyWithColors } from "../../stores/reducers/itemSlice";
3 c1161e82 Fantič
import { Certainty, Concordance } from "../../types/item";
4 a7a9a204 Fantič
import LoadingBox from "../loading/LoadingBox";
5 8ff3394e Fantič
import { DrawerNavigationProp } from "@react-navigation/drawer";
6 a62d7c92 Michal Schwob
import { RootStackParamList } from "../../pages/Navigation";
7 8ff3394e Fantič
import { InfoToast } from "../toast/InfoToast";
8 d281786c Fantič
9
// custom render Tab
10 f4af30c8 Fantič
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 d281786c Fantič
12 8ff3394e Fantič
    const { concordances, onIndexChange, index, onBackPressed, nextItem, prevItem } = props
13
14
    const toast = useToast();
15 d281786c Fantič
16 f4af30c8 Fantič
    console.log(concordances)
17
18 faf84222 Fantič
    if (concordances && concordances.length > 0) {
19 a7a9a204 Fantič
        return (
20 1054fe09 Fantič
            <VStack>
21 f4af30c8 Fantič
                {/* <HStack h="16" >
22 1054fe09 Fantič
                    <HStack width="50%">
23 091dec61 Fantič
                        <Button variant="ghost" size="lg" marginLeft={0}
24 1054fe09 Fantič
                            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 091dec61 Fantič
                            <Button variant="ghost" size="lg"
35 8ff3394e Fantič
                                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 1054fe09 Fantič
                                leftIcon={<ChevronLeftIcon size="lg" />}>
52
                            </Button>
53 091dec61 Fantič
                            <Button variant="ghost" size="lg"
54 8ff3394e Fantič
                                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 1054fe09 Fantič
                                leftIcon={<ChevronRightIcon size="lg" />}>
71
                            </Button>
72 faf84222 Fantič
                        </HStack>
73 1054fe09 Fantič
                    </HStack>
74 f4af30c8 Fantič
                </HStack> */}
75
                <View height={16} backgroundColor={"#F5F4F1"}>
76 1054fe09 Fantič
                    <ScrollView contentContainerStyle={{ flexGrow: 1 }} flex="1" horizontal={true}>
77
                        {props.navigationState.routes.length > 1 ? (
78 191f2cc7 Fantič
                            <HStack borderBottomWidth={1} flex="1" borderColor="light.400">
79 1054fe09 Fantič
                                {props.navigationState.routes.map((route, i) => {
80
                                    return (
81 f4af30c8 Fantič
                                        <Pressable onPress={() => { onIndexChange(i) }} width="100%">
82
                                        <VStack alignItems={"center"} >
83
                                            <HStack alignItems={"center"} width={32}>
84 1054fe09 Fantič
                                                <CircleIcon
85
                                                    size="2"
86 8ff3394e Fantič
                                                    color={CertaintyWithColors[concordances[i]?.cert ?? Certainty.Unknown].color}
87 1054fe09 Fantič
                                                />
88 f4af30c8 Fantič
                                                <Text marginLeft={1}>
89
                                                    <Text bold>{concordances[i]?.id}</Text>
90 191f2cc7 Fantič
                                                </Text>
91
                                            </HStack>
92 f4af30c8 Fantič
                                            {i == index && <Divider color="primary" borderWidth={1} width={30} mt={2} />}
93
                                        </VStack>
94
        
95
                                    </Pressable>
96 1054fe09 Fantič
                                    );
97
                                })}
98
                            </HStack>
99
                        ) : (
100
                            // One item only
101 f4af30c8 Fantič
102
103 191f2cc7 Fantič
                            <Pressable onPress={() => { onIndexChange(0) }} width="100%">
104 f4af30c8 Fantič
                                <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 1054fe09 Fantič
                        )}
119
                    </ScrollView>
120
                </View>
121
            </VStack>
122
123 faf84222 Fantič
        );
124
    }
125 d281786c Fantič
    else {
126 a7a9a204 Fantič
        return <LoadingBox text={`Loading concordances...`}></LoadingBox>
127 d281786c Fantič
    }
128 a7a9a204 Fantič
};
129 d281786c Fantič
130 a7a9a204 Fantič
export default ItemTabBar