import { View, Text, Alert, TouchableOpacity } from "react-native"; import TimeAgo from "@andordavoti/react-native-timeago"; import { router } from "expo-router"; import { styled } from "nativewind"; import utmObj from "utm-latlng"; type QueryItemProps = { name: string; volume: string; price: string; date: Date; storeKey: string; distance: Number; perFloz: Number; }; export default function QueryItem(props: QueryItemProps) { const utm = new utmObj(); const StyledText = styled(Text); const StyledTimeAgo = styled(TimeAgo); const distanceInMeters = Math.round(Number(props.distance)); const distance = distanceInMeters > 1609 ? `${Math.round(distanceInMeters / 1609)} mi.` : `${Math.round(distanceInMeters * 3.28084)} ft.`; const navToStore = async () => { const res = await fetch( `${process.env.EXPO_PUBLIC_BACKEND_URL}/?` + new URLSearchParams({ storeKey: props.storeKey, }) ); if (!res.ok) return Alert.alert( "Error!", "Server error. Please report to ak95@riseup.net" ); const json = await res.json(); const { lat, lng } = utm.convertUtmToLatLng( json.easting, json.northing, json.zone, json.zoneLetter ); router.push({ pathname: "/store/[coords]", params: { coords: `${lng}+${lat}`, }, }); }; return ( {props.name} ({props.volume} fl. oz.) ${props.price}  (${props.perFloz}/fl. oz.) {distance} away ); }