diff --git a/src/App.css b/src/App.css
index c7f4da8..8d34002 100644
--- a/src/App.css
+++ b/src/App.css
@@ -4,3 +4,26 @@
color: white;
text-align: center;
}
+
+.form-control {
+ display: block;
+ width: 100%;
+ padding: .375rem .75rem;
+ font-size: 1rem;
+ font-weight: 400;
+ line-height: 1.5;
+ color: #212529;
+ background-color: #fff;
+ background-clip: padding-box;
+ border: 1px solid #ced4da;
+ -webkit-appearance: none;
+ -moz-appearance: none;
+ appearance: none;
+ border-radius: .375rem;
+ transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
+}
+
+.my-5 {
+ margin-top: 3rem!important;
+ margin-bottom: 3rem!important;
+}
diff --git a/src/App.js b/src/App.js
index efe1118..d1444c3 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,13 +1,7 @@
import React from "react";
import "./App.css";
-
-function City(props) {
- return
This is the City component
;
-}
-
-function ZipSearchField(props) {
- return This is the ZipSearchField component
;
-}
+import City from "./City"
+import ZipSearchField from "./ZipSearchField";
function App() {
return (
@@ -17,10 +11,6 @@ function App() {
);
diff --git a/src/City.js b/src/City.js
new file mode 100644
index 0000000..6b103a0
--- /dev/null
+++ b/src/City.js
@@ -0,0 +1,17 @@
+import React from "react";
+
+export default function City({city}) {
+ return (
+
+
{city.City}, {city.State}
+
+
+ - State: {city.State}
+ - Location: ({city.Lat}, {city.Long})
+ - Population (estimated): {city.EstimatedPopulation}
+ - Total Wages: {city.TotalWages}
+
+
+
+ );
+}
\ No newline at end of file
diff --git a/src/ZipSearchField.js b/src/ZipSearchField.js
new file mode 100644
index 0000000..3dacf4f
--- /dev/null
+++ b/src/ZipSearchField.js
@@ -0,0 +1,53 @@
+import React, { useState } from "react";
+import City from "./City";
+
+export default function ZipSearchField(props) {
+ const [inputValue, setInputValue] = useState('');
+ const [errorMessage, setErrorMessage] = useState("No results found");
+ const [cityData, setCityData] = useState([]);
+
+ const handleInputChange = (event) => {
+ const zipCode = event.target.value;
+ setInputValue(zipCode);
+
+ if (zipCode.length === 5) {
+ fetch(`https://ctp-zip-code-api.onrender.com/zip/${zipCode}`)
+ .then((response) => {
+ if (!response.ok) {
+ throw new Error("Invalid response from server");
+ }
+ return response.json();
+ })
+ .then((data) => {
+ if (data.length > 0) {
+ setCityData(data);
+ setErrorMessage("");
+ } else {
+ setCityData([]);
+ setErrorMessage("No results found");
+ }
+ })
+ .catch((error) => {
+ console.error("Error fetching data:", error);
+ setCityData([]);
+ setErrorMessage("No results found");
+ });
+ } else {
+ setCityData([]);
+ setErrorMessage("No results found");
+ }
+ };
+ return (
+
+
+
+
+
+
+ {errorMessage &&
{errorMessage}}
+ {cityData.map((city, index) => (
+
+ ))}
+
+ );
+}
\ No newline at end of file