pogdark-app/components/Location.tsx

56 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-04-25 05:01:04 +00:00
import React, { useState } from "react";
import { Dialog, TextInput, useTheme, Button } from "react-native-paper";
import { View } from "react-native";
2025-04-25 04:44:06 +00:00
import axios from "axios";
2025-04-25 05:01:04 +00:00
import log from "@/util/log"
export const API_URL = process.env.EXPO_PUBLIC_API_URL;
const Location = () => {
2025-04-25 04:44:06 +00:00
const theme = useTheme();
2025-04-25 05:01:04 +00:00
const [zip, setZip] = useState("");
const [loading, setLoading] = useState(false);
const handleSubmit = async () => {
if (!zip) return;
setLoading(true);
try {
const response = await axios.post(API_URL + "/zipLookup", { zip });
log.error(response.data);
const long = response.data[0];
const lat = response.data[1];
} catch (err) {
// Optionally handle error
log.error(err);
}
setLoading(false);
};
2025-04-25 04:44:06 +00:00
return (
2025-04-25 04:44:06 +00:00
<Dialog.Content style={{ maxHeight: 300 }}>
2025-04-25 05:01:04 +00:00
<View style={{ flexDirection: "row", alignItems: "center", padding: 16 }}>
2025-04-25 04:44:06 +00:00
<TextInput
label="Enter Zip Code"
mode="outlined"
2025-04-25 05:01:04 +00:00
value={zip}
onChangeText={setZip}
style={{ flex: 1, marginRight: 10, fontFamily: "SpaceReg" }}
2025-04-25 04:44:06 +00:00
placeholderTextColor={theme.colors.primary}
textColor={theme.colors.primary}
2025-04-25 05:01:04 +00:00
theme={{ colors: { text: theme.colors.primary } }}
2025-04-25 04:44:06 +00:00
/>
2025-04-25 05:01:04 +00:00
<Button
mode="contained"
onPress={handleSubmit}
loading={loading}
disabled={!zip || loading}
>
Submit
</Button>
2025-04-25 04:44:06 +00:00
</View>
</Dialog.Content>
2025-04-25 05:01:04 +00:00
);
};
2025-04-25 05:01:04 +00:00
export default Location;