Projekt

Obecné

Profil

Stáhnout (6.47 KB) Statistiky
| Větev: | Tag: | Revize:
1 8ff3394e Fantič
import { HStack, CircleIcon, View, ScrollView, Button, Center, Heading, Pressable, Text, Box, Container, VStack, Icon, ArrowBackIcon, ChevronLeftIcon, ChevronRightIcon, useToast } 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 a62d7c92 Michal Schwob
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 faf84222 Fantič
    if (concordances && concordances.length > 0) {
17 a7a9a204 Fantič
        return (
18 1054fe09 Fantič
            <VStack>
19
                <HStack h="16" >
20
                    <HStack width="50%">
21 091dec61 Fantič
                        <Button variant="ghost" size="lg" marginLeft={0}
22 1054fe09 Fantič
                            onPress={onBackPressed}
23
                            leftIcon={<ChevronLeftIcon size="lg" />}>
24
                            Back
25
                        </Button>
26
                    </HStack>
27
                    <HStack width="50%">
28
                        <HStack width="50%">
29
30
                        </HStack>
31
                        <HStack marginRight={0}>
32 091dec61 Fantič
                            <Button variant="ghost" size="lg"
33 8ff3394e Fantič
                                onPress={() => {
34
                                    if(prevItem){
35
                                        console.log(prevItem)
36
                                        props.navigation.navigate("Item", { itemId: prevItem.toString() })
37
                                    }
38
                                    else{
39
                                        toast.show({
40
                                            render: ({
41
                                                id
42
                                            }) => {
43
                                                return <InfoToast text={"No previous item..."} onClose={() => toast.close(id)} />;
44
                                            },
45
                                            duration: 3000
46
                                        });
47
                                    }
48
                                }}
49 1054fe09 Fantič
                                leftIcon={<ChevronLeftIcon size="lg" />}>
50
                            </Button>
51 091dec61 Fantič
                            <Button variant="ghost" size="lg"
52 8ff3394e Fantič
                                onPress={() => {
53
                                    
54
                                    if(nextItem){
55
                                        props.navigation.navigate("Item", { itemId: nextItem.toString() })
56
                                    }
57
                                    else{
58
                                        toast.show({
59
                                            render: ({
60
                                                id
61
                                            }) => {
62
                                                return <InfoToast text={"No next item..."} onClose={() => toast.close(id)} />;
63
                                            },
64
                                            duration: 3000
65
                                        });
66
                                    }
67
                                }}
68 1054fe09 Fantič
                                leftIcon={<ChevronRightIcon size="lg" />}>
69
                            </Button>
70 faf84222 Fantič
                        </HStack>
71 1054fe09 Fantič
                    </HStack>
72
                </HStack>
73 191f2cc7 Fantič
                <View h="8">
74 1054fe09 Fantič
                    <ScrollView contentContainerStyle={{ flexGrow: 1 }} flex="1" horizontal={true}>
75
                        {props.navigationState.routes.length > 1 ? (
76 191f2cc7 Fantič
                            <HStack borderBottomWidth={1} flex="1" borderColor="light.400">
77 1054fe09 Fantič
                                {props.navigationState.routes.map((route, i) => {
78
                                    return (
79 191f2cc7 Fantič
                                        <Pressable key={i} onPress={() => { onIndexChange(i) }}>
80
                                            <HStack alignItems={"center"} width="32" borderColor="light.400" height="100%" borderBottomWidth={i == index ? 2 : 0}>
81 1054fe09 Fantič
                                                <CircleIcon
82 e0741b92 Fantič
                                                    marginLeft="5"
83 1054fe09 Fantič
                                                    size="2"
84 8ff3394e Fantič
                                                    color={CertaintyWithColors[concordances[i]?.cert ?? Certainty.Unknown].color}
85 1054fe09 Fantič
                                                />
86 191f2cc7 Fantič
                                                <Text marginLeft="5%">
87 8ff3394e Fantič
                                                    {i == index ? <Text bold>{concordances[i]?.id}</Text> : concordances[i]?.id}
88 191f2cc7 Fantič
89
                                                </Text>
90
                                            </HStack>
91
                                        </Pressable>
92 1054fe09 Fantič
                                    );
93
                                })}
94
                            </HStack>
95
                        ) : (
96
                            // One item only
97 191f2cc7 Fantič
                            <Pressable onPress={() => { onIndexChange(0) }} width="100%">
98
                                            <HStack alignItems={"center"} width="100%" borderColor="light.400" height="100%" borderBottomWidth={2}>
99
                                                <CircleIcon
100
                                                    marginLeft="42%"
101
                                                    size="2"
102 8ff3394e Fantič
                                                    color={CertaintyWithColors[concordances[0]?.cert ?? Certainty.Unknown].color}
103 191f2cc7 Fantič
                                                />
104
                                                <Text marginLeft="2%">
105 8ff3394e Fantič
                                                    <Text bold>{concordances[0]?.id}</Text>
106 191f2cc7 Fantič
                                                </Text>
107
                                            </HStack>
108
                                        </Pressable>
109 1054fe09 Fantič
                        )}
110
                    </ScrollView>
111
                </View>
112
            </VStack>
113
114 faf84222 Fantič
        );
115
    }
116 d281786c Fantič
    else {
117 a7a9a204 Fantič
        return <LoadingBox text={`Loading concordances...`}></LoadingBox>
118 d281786c Fantič
    }
119 a7a9a204 Fantič
};
120 d281786c Fantič
121 a7a9a204 Fantič
export default ItemTabBar