import { RefreshControl } from 'react-native'; import { TextInput, StatusBar, StyleSheet, Text, View, Image, ScrollView, } from 'react-native'; import AsyncStorage from '@react-native-async-storage/async-storage'; import {useIsFocused} from '@react-navigation/native'; import { useCallback, useEffect, useState } from 'react'; import AwesomeAlert from 'react-native-awesome-alerts'; import NetInfo from "@react-native-community/netinfo"; import { MenuProvider } from 'react-native-popup-menu'; import { Menu, MenuOptions, MenuOption, MenuTrigger, } from 'react-native-popup-menu'; type sendListDataProps = {route: any,navigation: any}; function SentListPermit({route,navigation}: sendListDataProps) { const [refreshing, setRefreshing] = useState(false); const onRefresh = useCallback(() => { setRefreshing(true); setTimeout(() => { setRefreshing(false); }, 2000); }, []); const [localStorage, setLocalStorage] = useState([]); const [filterData, setFilterData] = useState([]); const [alertOffline, setAlertOffline] = useState(false); const [connected, setConnected] = useState(true) const deleteById = (name:string) => { setLocalStorage(oldValues => { return oldValues.filter((local_data:any) => local_data.company_name !== name) }) }; const removeValue = async (key:string) => { try { console.log("keyDelete",key); await AsyncStorage.removeItem(key) // await getCount(); } catch(e) { } }; const getDataPermit = async () => { setLocalStorage([]) try { const jsonValue = await AsyncStorage.getAllKeys() if(jsonValue.length != 0) { jsonValue.map((item) => { if(item != "USER_DATA" && item != "my-jwt"){ let splited = item.split(" / "); if(splited.length === 6){ const objectItem = { id:splited[0], company_name:splited[1], permit_status:splited[2], location:splited[3], geom:splited[4].split(",") } console.log("aaa",objectItem); if(splited[5] === 'sentPermit'){ setLocalStorage(oldArray => [...oldArray,objectItem]) } } } }) } } catch (error) { } }; const isFocused = useIsFocused(); useEffect(() => { if(isFocused){ getDataPermit() const unsubscribe = NetInfo.addEventListener((state) => { setConnected(state.isConnected!) }); return () => { unsubscribe(); }; }; },[isFocused]) const [draftData, setDraftData] = useState(0); navigation.addListener('beforeRemove', (e:any)=> { }) const [stringFilter,setStingFilter] = useState('') const handleSearch = (text:string) => { const formattedQuery = text.toLowerCase(); const filteredData = localStorage.filter((data:any) => data.case_name.toLowerCase().includes(formattedQuery) ) setFilterData(filteredData) }; const optionsStyles = { optionsContainer: { alignItems: 'flex-start', justifyContent: 'center', width:100, marginVertical:-10, marginLeft:-10, backgroundColor: '#FFFFFF', borderRadius: 5, shadowColor: '#00000040', shadowOffset: { width: 0, height: 2, }, borderColor:'#6B5E5E4D', borderWidth:1, shadowOpacity: 0.2, shadowRadius: 6, elevation: 5, }, optionText: { color: 'brown', }, }; return( {handleSearch(queryText),setStingFilter(queryText)}} defaultValue={stringFilter} /> } > { localStorage.length != 0 ? localStorage.map((item:any,index:number) => ( Company Name Permit Status Location : {item.company_name} : {item.permit_status} : {item.location} { navigation.navigate('Permit Editing',{ screen: 'Edit',data: { id:item.id, company_name:item.company_name, permit_status:item.permit_status, location:item.location, }}); }} children={ Edit } /> { deleteById(item.company_name); removeValue(item.id+" / "+item.company_name+" / "+item.permit_status+" / "+item.location+" / "+item.geom+" / sentPermit"); }} children={ Delete } /> )) : Data Kosong } { setAlertOffline(false); }} overlayStyle={{width:'100%'}} contentContainerStyle={{width:'70%',borderRadius:10}} titleStyle={{fontSize:20}} messageStyle={{fontSize:16}} /> ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#ecf0f1', padding: 10, }, mainContainer: { flex: 1, }, title: { alignItems: 'center', justifyContent: 'center', alignSelf: 'center', fontWeight: 'bold', fontSize: 22, color: 'black', marginBottom: 10 }, input: { height: 40, borderWidth: 1, padding: 10, borderRadius: 50, color: 'black' }, }); export default SentListPermit;