|
@@ -1,42 +1,32 @@
|
|
|
import React, { FC, useEffect, useState } from 'react';
|
|
|
-import { FlatList as List, SafeAreaView } from 'react-native';
|
|
|
+import { FlatList as List, SafeAreaView, View } from 'react-native';
|
|
|
import { Input } from '../Input';
|
|
|
import { styles } from './styles';
|
|
|
import { Item, ItemData } from './item';
|
|
|
-
|
|
|
-const DATA: ItemData[] = [
|
|
|
- {
|
|
|
- id: '1',
|
|
|
- title: 'First Item'
|
|
|
- },
|
|
|
- {
|
|
|
- id: '2',
|
|
|
- title: 'Second Item'
|
|
|
- },
|
|
|
- {
|
|
|
- id: '3',
|
|
|
- title: 'Third Item'
|
|
|
- }
|
|
|
-];
|
|
|
+import { useGetRegionsWithFlagQuery } from '../../modules/auth/regions/queries/use-post-get-regions';
|
|
|
|
|
|
type Props = {
|
|
|
itemObject: (object: any) => void;
|
|
|
};
|
|
|
|
|
|
-//TODO: rework to generic types + custom props + fetch data
|
|
|
+//TODO: rework to generic types + custom props
|
|
|
|
|
|
export const FlatList: FC<Props> = ({ itemObject }) => {
|
|
|
- const [selectedObject, setSelectedObject] = useState<{ id: string; title: string }>();
|
|
|
+ const [selectedObject, setSelectedObject] = useState<{ name: string; id: number }>();
|
|
|
const [search, setSearch] = useState('');
|
|
|
const [filteredData, setFilteredData] = useState<ItemData[]>([]);
|
|
|
const [masterData, setMasterData] = useState<ItemData[]>([]);
|
|
|
|
|
|
+ const { data } = useGetRegionsWithFlagQuery(true);
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
- setFilteredData(DATA);
|
|
|
- setMasterData(DATA);
|
|
|
- }, []);
|
|
|
+ if (data) {
|
|
|
+ setFilteredData(data.data);
|
|
|
+ setMasterData(data.data);
|
|
|
+ }
|
|
|
+ }, [data]);
|
|
|
|
|
|
- const selectItem = (object: { title: string; id: string }) => {
|
|
|
+ const selectItem = (object: { name: string; id: number }) => {
|
|
|
itemObject(object);
|
|
|
setSelectedObject(object);
|
|
|
};
|
|
@@ -44,7 +34,7 @@ export const FlatList: FC<Props> = ({ itemObject }) => {
|
|
|
const searchFilter = (text: string) => {
|
|
|
if (text) {
|
|
|
const newData = masterData.filter((item) => {
|
|
|
- const itemData = item.title ? item.title.toLowerCase() : ''.toLowerCase();
|
|
|
+ const itemData = item.name ? item.name.toLowerCase() : ''.toLowerCase();
|
|
|
const textData = text.toLowerCase();
|
|
|
return itemData.indexOf(textData) > -1;
|
|
|
});
|
|
@@ -73,16 +63,18 @@ export const FlatList: FC<Props> = ({ itemObject }) => {
|
|
|
|
|
|
return (
|
|
|
<SafeAreaView style={styles.container}>
|
|
|
- <Input
|
|
|
- inputMode={'search'}
|
|
|
- placeholder={'test'}
|
|
|
- onChange={(text) => searchFilter(text)}
|
|
|
- value={search}
|
|
|
- />
|
|
|
+ <View style={{ marginTop: 10 }}>
|
|
|
+ <Input
|
|
|
+ inputMode={'search'}
|
|
|
+ placeholder={'Search'}
|
|
|
+ onChange={(text) => searchFilter(text)}
|
|
|
+ value={search}
|
|
|
+ />
|
|
|
+ </View>
|
|
|
<List
|
|
|
data={filteredData}
|
|
|
renderItem={renderItem}
|
|
|
- keyExtractor={(item) => item.id}
|
|
|
+ keyExtractor={(item) => item.id.toString()}
|
|
|
extraData={selectedObject}
|
|
|
/>
|
|
|
</SafeAreaView>
|