1
|
import { HStack, CircleIcon, View, ScrollView, Button, Center, Heading, Pressable, Text, Box, Container, VStack, Icon, ArrowBackIcon, ChevronLeftIcon, ChevronRightIcon, useToast } 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
|
if (concordances && concordances.length > 0) {
|
17
|
return (
|
18
|
<VStack>
|
19
|
<HStack h="16" >
|
20
|
<HStack width="50%">
|
21
|
<Button variant="ghost" size="lg" marginLeft={0}
|
22
|
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
|
<Button variant="ghost" size="lg"
|
33
|
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
|
leftIcon={<ChevronLeftIcon size="lg" />}>
|
50
|
</Button>
|
51
|
<Button variant="ghost" size="lg"
|
52
|
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
|
leftIcon={<ChevronRightIcon size="lg" />}>
|
69
|
</Button>
|
70
|
</HStack>
|
71
|
</HStack>
|
72
|
</HStack>
|
73
|
<View h="8">
|
74
|
<ScrollView contentContainerStyle={{ flexGrow: 1 }} flex="1" horizontal={true}>
|
75
|
{props.navigationState.routes.length > 1 ? (
|
76
|
<HStack borderBottomWidth={1} flex="1" borderColor="light.400">
|
77
|
{props.navigationState.routes.map((route, i) => {
|
78
|
return (
|
79
|
<Pressable key={i} onPress={() => { onIndexChange(i) }}>
|
80
|
<HStack alignItems={"center"} width="32" borderColor="light.400" height="100%" borderBottomWidth={i == index ? 2 : 0}>
|
81
|
<CircleIcon
|
82
|
marginLeft="5"
|
83
|
size="2"
|
84
|
color={CertaintyWithColors[concordances[i]?.cert ?? Certainty.Unknown].color}
|
85
|
/>
|
86
|
<Text marginLeft="5%">
|
87
|
{i == index ? <Text bold>{concordances[i]?.id}</Text> : concordances[i]?.id}
|
88
|
|
89
|
</Text>
|
90
|
</HStack>
|
91
|
</Pressable>
|
92
|
);
|
93
|
})}
|
94
|
</HStack>
|
95
|
) : (
|
96
|
// One item only
|
97
|
<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
|
color={CertaintyWithColors[concordances[0]?.cert ?? Certainty.Unknown].color}
|
103
|
/>
|
104
|
<Text marginLeft="2%">
|
105
|
<Text bold>{concordances[0]?.id}</Text>
|
106
|
</Text>
|
107
|
</HStack>
|
108
|
</Pressable>
|
109
|
)}
|
110
|
</ScrollView>
|
111
|
</View>
|
112
|
</VStack>
|
113
|
|
114
|
);
|
115
|
}
|
116
|
else {
|
117
|
return <LoadingBox text={`Loading concordances...`}></LoadingBox>
|
118
|
}
|
119
|
};
|
120
|
|
121
|
export default ItemTabBar
|