import React, { useEffect, useState } from 'react' import { Image, View, Text, StyleSheet, TouchableOpacity, ActivityIndicator, Platform } from 'react-native'; import { returnStatus, returnIcon, returnStatusId } from '../../../../utils/IQAIRhelper'; import { useSelector } from 'react-redux'; import Icon from '../../../../components/icons'; import API from '../../../../components/api/iqair'; import Theme from '../../../../components/theme.style'; import Elements from '../../../../components/elements'; import { useNavigation } from '@react-navigation/native'; const IQAIRDetails = (props) => { const navigation = useNavigation(); const app_theme = useSelector(state => state.appThemeReducer.theme); const dark = app_theme.theme.dark; const [IQAir, setIQAir] = useState(undefined); const [loading, setLoading] = useState(false); const [ID, setID] = useState(0); useEffect(() => { if(props.selected) init(); }, [props.selected]) const init = () => { setLoading(true); setTimeout(() => { const data = { lat: props.selected.latitude, lon: props.selected.longitude } API(data, (res) => { const aqius = res.data.current.pollution.aqius || res.data.current.weather.tp; setID(returnStatusId(aqius)); setIQAir(res.data.current); setLoading(false); }, (err) =>{ setTimeout(() => { init(); }, 2000) }) }, 1000) } const onPress = () => { navigation.navigate("Details", { value: { item: props.item }, iqairData: IQAir, id: ID }) } if(!props.selected) return null; return ( { Platform.OS === 'android' ? : } {props.item.name} {props.item.address} { loading ? : <> {IQAir?.pollution.aqius || IQAir?.weather.tp} * US AQI {returnStatus(ID).title} } { loading ? : <> {IQAir?.weather.hu}% {(IQAir?.weather.ws * 3.6).toFixed(2)} km/h {IQAir?.weather.tp}° } ) } export default IQAIRDetails const styles = StyleSheet.create({ container: { position: 'absolute', bottom: 0, left: 0, right: 0, paddingVertical: 10, paddingHorizontal: 10 }, renderItem: { backgroundColor: 'white', borderRadius: 5, marginHorizontal: 18, paddingHorizontal: 10, paddingBottom: 10, paddingVertical: 8, }, firstRow: { flexDirection: 'row', height: 50, }, infoContainer: { flex: 1, marginLeft: 8 }, nameText: { color: Theme.colors.searchText, fontSize: 14 }, addressText: { color: Theme.colors.searchText, fontSize: 10, marginTop: 2 }, secondRow: { flexDirection: 'row', height: 70, flex: 1, marginTop: 5 }, iconContainer: { flex: .25, backgroundColor: Theme.colors.whitesmoke, alignItems: 'center', justifyContent: 'center', borderTopLeftRadius: 5, borderBottomLeftRadius: 5 }, iconShadow: { alignItems: 'center', justifyContent: 'center' }, icon: { height: '75%', resizeMode: 'contain', }, airlevelContainer: (id) => { return { flex: .33, backgroundColor: Theme.colors.iqair[id].opacity, alignItems: 'center', justifyContent: 'center' } }, airlevelTitle: { color: Theme.colors.white, fontSize: 25 }, airlevelIndicator: { color: Theme.colors.white, fontSize: 11 }, statusContainer: (id) => { return { flex: .5, borderRadius: 5, backgroundColor: Theme.colors.iqair[id].main, left: -10, justifyContent: 'center', alignItems: 'center' } }, statusText: { color: Theme.colors.white, fontSize: 12, fontWeight: 'bold', textAlign: 'center' }, thirdRow: { flexDirection: 'row', flex: 1, height: 20, alignItems: 'center', marginTop: 14, marginBottom: 5 }, water: { flex: .25, borderRightWidth: 1, borderColor: Theme.colors.gray, flexDirection: 'row', alignItems: 'center' }, waterIcon: { marginRight: 3, height: 15, width: 15, resizeMode: 'contain' }, wind: { flex: .33, flexDirection: 'row', alignItems: 'center' }, airIcon: { height: 20, width: 20, marginLeft: 10, resizeMode: 'contain' }, cloud: { left: -10, flex: .37, borderColor: Theme.colors.gray, borderLeftWidth: 1, flexDirection: 'row', alignItems: 'center' }, cloudIcon: { height: 20, width: 20, resizeMode: 'contain', marginHorizontal: 4, marginLeft: 15 }, activityIndicator: { flex: 1, alignItems: 'center', justifyContent: 'center' }, infoText: { fontSize: 10, color: Theme.colors.searchText }, darkColor: (appTheme) => { if(appTheme?.theme.dark) { return { color: Theme.colors.white } } }, darkBackground: (appTheme) => { return { backgroundColor: appTheme?.theme.colors.border } } })