diff --git a/src/App.css b/src/App.css
index c7f4da8..f6f9a41 100644
--- a/src/App.css
+++ b/src/App.css
@@ -4,3 +4,20 @@
color: white;
text-align: center;
}
+.label{
+ margin-top: 10px;
+ font-weight: bold;
+}
+
+.zipSearchField{
+ margin-top: 20px;
+}
+.city{
+ background-color: rgb(204 205 203);
+ padding-left: 10px;
+ font-weight: 500;
+}
+.fields{
+ padding: 10px 60px 10px 60px;
+ font-weight:500 ;
+}
\ No newline at end of file
diff --git a/src/App.jsx b/src/App.jsx
index 6478b09..787f935 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -1,25 +1,126 @@
-import { useState } from "react";
+import { useState, useEffect } from "react";
import "./App.css";
function City(props) {
- return
This is the City component
;
+ const[formattedCityName, setFormattedCityName] = useState("")
+
+
+ function toTitleCase(str) {
+ let formatted_name = str.toLowerCase().split(' ').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ');
+ setFormattedCityName(formatted_name);
+ }
+
+ useEffect(()=>{
+ toTitleCase(props.city);
+ }, [props])
+
+ return (
+
+
{`${formattedCityName}, ${props.state}`}
+
+ -
+ State: {props.state}
+
+ -
+ Location: {`(${props.lat}, ${props.long})`}
+
+ -
+ Population (estimated): {props.population}
+
+ -
+ Total Wages: {" "} {props.totalWages}
+
+
+
+ );
}
function ZipSearchField(props) {
- return This is the ZipSearchField component
;
+
+ const [input, setInput] = useState("");
+
+ function handleChange(newInput){
+ const text = newInput.target.value
+ setInput(text)
+ }
+
+
+ // async function fetchCities(zips){
+ // const endpoint = `https://ctp-zip-code-api.onrender.com/zip/${input}`;
+ // fetch(endpoint)
+ // .then((response) => response.json())
+ // .then((data) => {
+ // console.log("data", data);
+ // })
+ // .catch((err) => {
+ // alert("An error occurred when getting the information."),
+ // console.log("Error fetching from endpoint: ", err);
+ // });
+ // }
+ function handleSubmit(e){
+ e.preventDefault();
+ console.log(input)
+ if(input === ""){
+ return
+ }
+ if(parseInt(input)){
+ const endpoint = `https://ctp-zip-code-api.onrender.com/zip/${input}`;
+ fetch(endpoint)
+ .then((response) =>response.json())
+ .then( data => {console.log("data", data); props.copyResults(data)})
+ .catch(err=>{alert("An error occurred when getting the information."), console.log("Error fetching from endpoint: ",err)})
+ // }else{
+ // const upper_input = input.toUpperCase();
+ // const endpoint = `https://ctp-zip-code-api.onrender.com/city/${upper_input}`;
+ // fetch(endpoint)
+ // .then((response) =>
+ // response.json()
+ // )
+ // .then((data) => fetchCity(data))
+ // .catch((err) => {
+ // alert("An error occurred when getting the information."),
+ // console.log("Error fetching from endpoint: ", err);
+ // });
+ }
+}
+ return (
+
+
+
+ );
}
function App() {
+ const [results, setResults] = useState([]);
+
+ function copyResults(data){
+ setResults(data);
+ }
return (
Zip Code Search
-
+
-
-
+ {
+
+ results.map((result, index)=>(
+
+ ))
+ }