diff --git a/src/App.css b/src/App.css index c7f4da8..296d56c 100644 --- a/src/App.css +++ b/src/App.css @@ -1,6 +1,35 @@ .App-header { - background-color: #222; - padding: 20px; - color: white; - text-align: center; + background-color: #222; + padding: 20px; + color: white; + text-align: center; +} + +.city-box { + border: 1px solid #ccc; + padding: 15px; + margin-top: 10px; + background-color: #f9f9f9; + border-radius: 8px; + box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1); +} + +.city-box h3 { + margin-bottom: 5px; +} + +.city-box p { + margin: 5px 0; +} + +.App-header { + text-align: center; + margin-bottom: 20px; +} + +input { + width: 100%; + padding: 10px; + margin: 10px 0; + box-sizing: border-box; } diff --git a/src/App.jsx b/src/App.jsx index 6478b09..07dcb1e 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,26 +1,97 @@ import { useState } from "react"; import "./App.css"; -function City(props) { - return
This is the City component
; +function City({ cityData }) { + return ( +
+

+ {cityData.City}, {cityData.State} +

+

State: {cityData.State}

+

+ Location: ({cityData.Lat}, {cityData.Long}) +

+

Population (estimated): {cityData.EstimatedPopulation}

+

Total Wages: {cityData.TotalWages}

+
+ ); } -function ZipSearchField(props) { - return
This is the ZipSearchField component
; +function ZipSearchField({ zipCode, setZipCode, onSearch }) { + return ( +
+ + setZipCode(e.target.value)} + placeholder="Enter Zip Code" + style={{ padding: "10px", fontSize: "1.2em", marginRight: "10px" }} + /> + +
+ ); } function App() { + const [zipCode, setZipCode] = useState(""); + const [cities, setCities] = useState([]); + const [error, setError] = useState(false); + + const fetchCityData = async () => { + if (zipCode.length !== 5) { + setCities([]); + setError(true); + return; + } + + try { + const response = await fetch( + `https://ctp-zip-code-api.onrender.com/zip/${zipCode}` + ); + if (!response.ok) throw new Error("No results found"); + + const data = await response.json(); + setCities(data); + setError(false); + } catch { + setCities([]); + setError(true); + } + }; + + const handleSearch = () => { + fetchCityData(); + }; + return ( -
-
+
+

Zip Code Search

-
- -
- - -
+
+ + {error ? ( +
No results found
+ ) : ( +
+ {cities.map((city) => ( + + ))} +
+ )}
); diff --git a/vite.config.js b/vite.config.js index 97f4bc5..ee6a7b2 100644 --- a/vite.config.js +++ b/vite.config.js @@ -4,5 +4,5 @@ import react from "@vitejs/plugin-react"; // https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], - base: "/lab-react-zip-search/", + // base: "/lab-react-zip-search/", // Remove this line for Netlify/Vercel });