import { useState } from "react"; import { TouchableOpacity, View, Text, TextInput, Alert } from "react-native"; import { styled } from "nativewind"; import { FontAwesome5 } from "@expo/vector-icons"; import { Ionicons } from "@expo/vector-icons"; import TimeAgo from "@andordavoti/react-native-timeago"; type StoreItemProps = { name: string; volume: string; price: string; date: Date; storeKey: string; }; export default function StoreItem(props: StoreItemProps) { const StyledText = styled(Text); const StyledTimeAgo = styled(TimeAgo); const StyledFontAwesome = styled(FontAwesome5); const StyledIonicons = styled(Ionicons); const [editing, setEditing] = useState(false); const [locked, setLocked] = useState(false); const [price, setPrice] = useState(props.price); const updatePrice = async () => { setLocked(true); const res = await fetch( `${process.env.EXPO_PUBLIC_BACKEND_URL}/?` + new URLSearchParams({ storeKey: props.storeKey, itemName: props.name, itemPrice: price, }), { method: "PUT", mode: "cors", redirect: "follow", } ); if (!res.ok) Alert.alert("Error!", "Server error. Please report to ak95@riseup.net"); setLocked(false); setEditing(!editing); }; return ( {props.name} {props.volume} Fl. Oz. $ {editing ? ( { if (!locked) { if (text.includes(".")) { const split = text.split("."); if (split.length < 3) { const righthand = split[1]; if (righthand.length <= 2) { setPrice(text); } } } else setPrice(text); } }} inputMode="decimal" value={price} /> ) : ( {price}  setEditing(!editing)}> )} ); }