|
@@ -4,7 +4,7 @@ import * as Progress from 'react-native-progress';
|
|
import { useFocusEffect, useNavigation } from '@react-navigation/native';
|
|
import { useFocusEffect, useNavigation } from '@react-navigation/native';
|
|
import moment from 'moment';
|
|
import moment from 'moment';
|
|
|
|
|
|
-import { EditNmModal, Header, PageWrapper } from 'src/components';
|
|
|
|
|
|
+import { EditNmModal, Header, Input, PageWrapper } from 'src/components';
|
|
import { CustomButton } from '../Components';
|
|
import { CustomButton } from '../Components';
|
|
import { NmRegionItem } from '../Components/MyRegionsItems/NmRegionItem';
|
|
import { NmRegionItem } from '../Components/MyRegionsItems/NmRegionItem';
|
|
import { RegionItem } from '../Components/MyRegionsItems/RegionItem';
|
|
import { RegionItem } from '../Components/MyRegionsItems/RegionItem';
|
|
@@ -24,6 +24,7 @@ import { qualityOptions } from '../utils/constants';
|
|
import ChevronIcon from 'assets/icons/travels-screens/down-arrow.svg';
|
|
import ChevronIcon from 'assets/icons/travels-screens/down-arrow.svg';
|
|
import { NAVIGATION_PAGES } from 'src/types';
|
|
import { NAVIGATION_PAGES } from 'src/types';
|
|
import { useRegion } from 'src/contexts/RegionContext';
|
|
import { useRegion } from 'src/contexts/RegionContext';
|
|
|
|
+import SearchIcon from 'assets/icons/search.svg';
|
|
|
|
|
|
const RegionsScreen = () => {
|
|
const RegionsScreen = () => {
|
|
const token = storage.get('token', StoreType.STRING) as string;
|
|
const token = storage.get('token', StoreType.STRING) as string;
|
|
@@ -51,6 +52,7 @@ const RegionsScreen = () => {
|
|
});
|
|
});
|
|
const navigation = useNavigation();
|
|
const navigation = useNavigation();
|
|
const { handleUpdateNMList: handleUpdateNM, nmRegions, setNmRegions, setUserData } = useRegion();
|
|
const { handleUpdateNMList: handleUpdateNM, nmRegions, setNmRegions, setUserData } = useRegion();
|
|
|
|
+ const [search, setSearch] = useState<string>('');
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
const currentYear = moment().year();
|
|
const currentYear = moment().year();
|
|
@@ -121,22 +123,43 @@ const RegionsScreen = () => {
|
|
}
|
|
}
|
|
}, [selectedMega]);
|
|
}, [selectedMega]);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
|
+ const applyFilters = () => {
|
|
|
|
+ let newNmData = nmRegions ?? [];
|
|
|
|
+ let newTccData = tccRegions ?? [];
|
|
|
|
+
|
|
switch (contentIndex) {
|
|
switch (contentIndex) {
|
|
- case 0:
|
|
|
|
- setFilteredNmRegions(nmRegions);
|
|
|
|
- setFilteredTccRegions(tccRegions);
|
|
|
|
- break;
|
|
|
|
case 1:
|
|
case 1:
|
|
- setFilteredNmRegions(nmRegions?.filter((item: NmRegion) => item.visits <= 0) || []);
|
|
|
|
- setFilteredTccRegions(tccRegions?.filter((item) => item.visited <= 0) || []);
|
|
|
|
|
|
+ newNmData = nmRegions?.filter((item: NmRegion) => item.visits <= 0) || [];
|
|
|
|
+ newTccData = tccRegions?.filter((item) => item.visited <= 0) || [];
|
|
break;
|
|
break;
|
|
case 2:
|
|
case 2:
|
|
- setFilteredNmRegions(nmRegions?.filter((item: NmRegion) => item.visits > 0) || []);
|
|
|
|
- setFilteredTccRegions(tccRegions?.filter((item) => item.visited > 0) || []);
|
|
|
|
|
|
+ newNmData = nmRegions?.filter((item: NmRegion) => item.visits > 0) || [];
|
|
|
|
+ newTccData = tccRegions?.filter((item) => item.visited > 0) || [];
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- }, [contentIndex, nmRegions, tccRegions]);
|
|
|
|
|
|
+
|
|
|
|
+ if (search) {
|
|
|
|
+ newNmData = newNmData?.filter((item: NmRegion) => {
|
|
|
|
+ const itemData = item.region_name ? item.region_name.toLowerCase() : '';
|
|
|
|
+ return itemData.includes(search.toLowerCase());
|
|
|
|
+ });
|
|
|
|
+ newTccData = newTccData?.filter((item: TCCRegion) => {
|
|
|
|
+ const itemData = item.name ? item.name.toLowerCase() : '';
|
|
|
|
+ return itemData.includes(search.toLowerCase());
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ setFilteredNmRegions(newNmData);
|
|
|
|
+ setFilteredTccRegions(newTccData);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ applyFilters();
|
|
|
|
+ }, [contentIndex, nmRegions, tccRegions, search]);
|
|
|
|
+
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ setSearch('');
|
|
|
|
+ }, [contentIndex, selectedMega]);
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
if (megaregions && megaregions.result === 'OK') {
|
|
if (megaregions && megaregions.result === 'OK') {
|
|
@@ -149,6 +172,10 @@ const RegionsScreen = () => {
|
|
setTotal(visited);
|
|
setTotal(visited);
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ const searchFilter = (text: string) => {
|
|
|
|
+ setSearch(text);
|
|
|
|
+ };
|
|
|
|
+
|
|
const renderItem = ({ item }: { item: NmRegion }) => (
|
|
const renderItem = ({ item }: { item: NmRegion }) => (
|
|
<TouchableOpacity
|
|
<TouchableOpacity
|
|
onPress={() => {
|
|
onPress={() => {
|
|
@@ -203,6 +230,17 @@ const RegionsScreen = () => {
|
|
<ChevronIcon width={18} height={18} />
|
|
<ChevronIcon width={18} height={18} />
|
|
</TouchableOpacity>
|
|
</TouchableOpacity>
|
|
|
|
|
|
|
|
+ <View style={{ marginBottom: 16 }}>
|
|
|
|
+ <Input
|
|
|
|
+ inputMode={'search'}
|
|
|
|
+ placeholder={'Search'}
|
|
|
|
+ onChange={(text) => searchFilter(text)}
|
|
|
|
+ value={search}
|
|
|
|
+ icon={<SearchIcon fill={'#C8C8C8'} width={14} height={14} />}
|
|
|
|
+ height={34}
|
|
|
|
+ />
|
|
|
|
+ </View>
|
|
|
|
+
|
|
{token && (
|
|
{token && (
|
|
<View style={styles.buttonContainer}>
|
|
<View style={styles.buttonContainer}>
|
|
<CustomButton
|
|
<CustomButton
|