|
@@ -1,14 +1,14 @@
|
|
|
-import React, { useCallback, useEffect, useState } from 'react';
|
|
|
|
|
|
|
+import React, { useEffect, useState } from 'react';
|
|
|
import { FlatList, Text, View, Image, TouchableOpacity } from 'react-native';
|
|
import { FlatList, Text, View, Image, TouchableOpacity } from 'react-native';
|
|
|
-import { useFocusEffect, useNavigation } from '@react-navigation/native';
|
|
|
|
|
|
|
+import { useNavigation } from '@react-navigation/native';
|
|
|
|
|
|
|
|
-import { Header, Loading, PageWrapper } from '../../../../components';
|
|
|
|
|
|
|
+import { Header, PageWrapper } from '../../../../components';
|
|
|
|
|
|
|
|
-import { getFontSize } from 'src/utils';
|
|
|
|
|
import { ItemStyles } from '../../TravellersScreen/Components/styles';
|
|
import { ItemStyles } from '../../TravellersScreen/Components/styles';
|
|
|
import { API_HOST } from 'src/constants';
|
|
import { API_HOST } from 'src/constants';
|
|
|
import { Colors } from 'src/theme';
|
|
import { Colors } from 'src/theme';
|
|
|
import { NAVIGATION_PAGES } from 'src/types';
|
|
import { NAVIGATION_PAGES } from 'src/types';
|
|
|
|
|
+import { AccordionListItem } from './AccordionListItem';
|
|
|
|
|
|
|
|
const RegionsVisitedScreen = ({ route }: { route: any }) => {
|
|
const RegionsVisitedScreen = ({ route }: { route: any }) => {
|
|
|
const title = route.params.title;
|
|
const title = route.params.title;
|
|
@@ -18,6 +18,7 @@ const RegionsVisitedScreen = ({ route }: { route: any }) => {
|
|
|
|
|
|
|
|
const [sorted, setSorted] = useState(data);
|
|
const [sorted, setSorted] = useState(data);
|
|
|
const [sortDirection, setSortDirection] = useState<'asc' | 'desc'>('desc');
|
|
const [sortDirection, setSortDirection] = useState<'asc' | 'desc'>('desc');
|
|
|
|
|
+ const [expandedIds, setExpandedIds] = useState<number[]>([]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
setSorted([...data].sort((a, b) => b.days_spent - a.days_spent));
|
|
setSorted([...data].sort((a, b) => b.days_spent - a.days_spent));
|
|
@@ -34,6 +35,10 @@ const RegionsVisitedScreen = ({ route }: { route: any }) => {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ const sortedRegions = (regions: { id: number; region: string; days_spent: number }[]) => {
|
|
|
|
|
+ return regions.sort((a, b) => b.days_spent - a.days_spent);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<PageWrapper style={{ flex: 1 }}>
|
|
<PageWrapper style={{ flex: 1 }}>
|
|
|
<Header label={title} />
|
|
<Header label={title} />
|
|
@@ -43,81 +48,68 @@ const RegionsVisitedScreen = ({ route }: { route: any }) => {
|
|
|
style={{ flex: 1 }}
|
|
style={{ flex: 1 }}
|
|
|
horizontal={false}
|
|
horizontal={false}
|
|
|
data={sorted as any}
|
|
data={sorted as any}
|
|
|
- keyExtractor={(item, index) => index.toString()}
|
|
|
|
|
|
|
+ keyExtractor={(item, index) => item.id.toString()}
|
|
|
initialNumToRender={20}
|
|
initialNumToRender={20}
|
|
|
renderItem={({ item, index }) => {
|
|
renderItem={({ item, index }) => {
|
|
|
|
|
+ let subname = '';
|
|
|
const [name, ...rest] = isRegion ? item.region?.split(/ – | - /) : ['', ''];
|
|
const [name, ...rest] = isRegion ? item.region?.split(/ – | - /) : ['', ''];
|
|
|
- const subname = rest?.join(' - ');
|
|
|
|
|
|
|
+ if (isRegion) {
|
|
|
|
|
+ subname = rest?.join(' - ');
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- return (
|
|
|
|
|
|
|
+ return isRegion ? (
|
|
|
<TouchableOpacity
|
|
<TouchableOpacity
|
|
|
onPress={() =>
|
|
onPress={() =>
|
|
|
- isRegion
|
|
|
|
|
- ? navigation.navigate(
|
|
|
|
|
- ...([
|
|
|
|
|
- NAVIGATION_PAGES.REGION_PREVIEW,
|
|
|
|
|
- {
|
|
|
|
|
- regionId: item.id,
|
|
|
|
|
- isTravelsScreen: true,
|
|
|
|
|
- type: 'nm',
|
|
|
|
|
- disabled: false
|
|
|
|
|
- }
|
|
|
|
|
- ] as never)
|
|
|
|
|
- )
|
|
|
|
|
- : navigation.navigate(
|
|
|
|
|
- ...([
|
|
|
|
|
- NAVIGATION_PAGES.COUNTRY_PREVIEW,
|
|
|
|
|
- {
|
|
|
|
|
- regionId: item.id,
|
|
|
|
|
- isTravelsScreen: true,
|
|
|
|
|
- type: 'country',
|
|
|
|
|
- disabled: false
|
|
|
|
|
- }
|
|
|
|
|
- ] as never)
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ navigation.navigate(
|
|
|
|
|
+ ...([
|
|
|
|
|
+ NAVIGATION_PAGES.REGION_PREVIEW,
|
|
|
|
|
+ {
|
|
|
|
|
+ regionId: item.id,
|
|
|
|
|
+ isTravelsScreen: true,
|
|
|
|
|
+ type: 'nm',
|
|
|
|
|
+ disabled: false
|
|
|
|
|
+ }
|
|
|
|
|
+ ] as never)
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
style={[ItemStyles.wrapper, { paddingHorizontal: 8 }]}
|
|
style={[ItemStyles.wrapper, { paddingHorizontal: 8 }]}
|
|
|
>
|
|
>
|
|
|
- {isRegion ? (
|
|
|
|
|
- <>
|
|
|
|
|
|
|
+ <>
|
|
|
|
|
+ <Image
|
|
|
|
|
+ source={{
|
|
|
|
|
+ uri: API_HOST + item.flag1
|
|
|
|
|
+ }}
|
|
|
|
|
+ style={{
|
|
|
|
|
+ width: 32,
|
|
|
|
|
+ height: 32,
|
|
|
|
|
+ borderRadius: 32 / 2,
|
|
|
|
|
+ borderWidth: 1,
|
|
|
|
|
+ borderColor: Colors.FILL_LIGHT
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ {item?.flag2 ? (
|
|
|
<Image
|
|
<Image
|
|
|
- source={{
|
|
|
|
|
- uri: API_HOST + item.flag1
|
|
|
|
|
- }}
|
|
|
|
|
- style={{
|
|
|
|
|
- width: 32,
|
|
|
|
|
- height: 32,
|
|
|
|
|
- borderRadius: 32 / 2,
|
|
|
|
|
- borderWidth: 1,
|
|
|
|
|
- borderColor: Colors.FILL_LIGHT
|
|
|
|
|
- }}
|
|
|
|
|
|
|
+ source={{ uri: API_HOST + item.flag2 }}
|
|
|
|
|
+ style={[
|
|
|
|
|
+ {
|
|
|
|
|
+ width: 32,
|
|
|
|
|
+ height: 32,
|
|
|
|
|
+ borderRadius: 32 / 2,
|
|
|
|
|
+ borderWidth: 1,
|
|
|
|
|
+ borderColor: Colors.FILL_LIGHT,
|
|
|
|
|
+ marginLeft: -18
|
|
|
|
|
+ }
|
|
|
|
|
+ ]}
|
|
|
/>
|
|
/>
|
|
|
- {item?.flag2 ? (
|
|
|
|
|
- <Image
|
|
|
|
|
- source={{ uri: API_HOST + item.flag2 }}
|
|
|
|
|
- style={[
|
|
|
|
|
- {
|
|
|
|
|
- width: 32,
|
|
|
|
|
- height: 32,
|
|
|
|
|
- borderRadius: 32 / 2,
|
|
|
|
|
- borderWidth: 1,
|
|
|
|
|
- borderColor: Colors.FILL_LIGHT,
|
|
|
|
|
- marginLeft: -18
|
|
|
|
|
- }
|
|
|
|
|
- ]}
|
|
|
|
|
- />
|
|
|
|
|
- ) : null}
|
|
|
|
|
- </>
|
|
|
|
|
- ) : (
|
|
|
|
|
- <Image style={ItemStyles.bigFlag} source={{ uri: API_HOST + item.flag }} />
|
|
|
|
|
- )}
|
|
|
|
|
|
|
+ ) : null}
|
|
|
|
|
+ </>
|
|
|
|
|
|
|
|
<View style={[ItemStyles.contentWrapper, { gap: 4 }]}>
|
|
<View style={[ItemStyles.contentWrapper, { gap: 4 }]}>
|
|
|
<View style={{ flex: 1 }}>
|
|
<View style={{ flex: 1 }}>
|
|
|
<Text style={[{ color: Colors.DARK_BLUE, fontWeight: '600', fontSize: 15 }]}>
|
|
<Text style={[{ color: Colors.DARK_BLUE, fontWeight: '600', fontSize: 15 }]}>
|
|
|
- {isRegion ? name : item.country}
|
|
|
|
|
|
|
+ {name}
|
|
|
</Text>
|
|
</Text>
|
|
|
- {isRegion && subname ? (
|
|
|
|
|
|
|
+ {subname ? (
|
|
|
<Text style={[{ color: Colors.TEXT_GRAY, fontSize: 13 }]}>{subname}</Text>
|
|
<Text style={[{ color: Colors.TEXT_GRAY, fontSize: 13 }]}>{subname}</Text>
|
|
|
) : null}
|
|
) : null}
|
|
|
</View>
|
|
</View>
|
|
@@ -132,6 +124,17 @@ const RegionsVisitedScreen = ({ route }: { route: any }) => {
|
|
|
</Text>
|
|
</Text>
|
|
|
</View>
|
|
</View>
|
|
|
</TouchableOpacity>
|
|
</TouchableOpacity>
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <AccordionListItem
|
|
|
|
|
+ id={item.id}
|
|
|
|
|
+ name={item.country}
|
|
|
|
|
+ daysSpent={item.days_spent}
|
|
|
|
|
+ flag={item.flag}
|
|
|
|
|
+ regions={sortedRegions(item.regions)}
|
|
|
|
|
+ navigation={navigation}
|
|
|
|
|
+ expandedIds={expandedIds}
|
|
|
|
|
+ setExpandedIds={setExpandedIds}
|
|
|
|
|
+ />
|
|
|
);
|
|
);
|
|
|
}}
|
|
}}
|
|
|
showsVerticalScrollIndicator={false}
|
|
showsVerticalScrollIndicator={false}
|