Skip to content
This repository was archived by the owner on Sep 13, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions zip-search/src/App.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #222;
padding: 20px;
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
text-align: center;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
39 changes: 11 additions & 28 deletions zip-search/src/App.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
import React, { Component } from 'react';
import './App.css';


function City(props) {
return (<div>This is the City component</div>);
}

function ZipSearchField(props) {
return (<div>This is the ZipSearchField component</div>);
}


class App extends Component {
render() {
return (
<div className="App">
<div className="App-header">
<h2>Zip Code Search</h2>
</div>
<ZipSearchField />
<div>
<City />
<City />
</div>
</div>
);
}
import React from "react";
import Header from "./Header";
import SearchQuery from "./SearchQuery";

function App() {
return (
<div>
<Header />
<SearchQuery />
</div>
);
}

export default App;
8 changes: 8 additions & 0 deletions zip-search/src/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { render, screen } from '@testing-library/react';
import App from './App';

test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
11 changes: 11 additions & 0 deletions zip-search/src/Header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";

function Header() {
return (
<header>
<p>Zip Code Search</p>
</header>
);
}

export default Header;
64 changes: 64 additions & 0 deletions zip-search/src/SearchQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React, { Component } from "react";

class SearchQuery extends Component {
constructor() {
super();
this.state = {
query: '',
zipCodes: []
};

//resets state to initial state
this.initialState = { ...this.state };

this.handleSubmit = this.handleSubmit.bind(this);
this.handleSearch = this.handleSearch.bind(this);
}

handleSubmit(event) {
const { name, value } = event.target;
this.setState({ [name]: value });
}

handleSearch(event) {
event.preventDefault();
fetch('http://ctp-zip-api.herokuapp.com/city/' + this.state.query.toUpperCase() + '')
.then(response => response.json())
.then(response => { this.setState({ zipCodes: response })
})
.catch((error) => { this.setState({zipCodes: ['Invalid City. Check your input.'] })
})
console.log("after");
console.log(this.state.zipCodes);
this.setState(this.initialState);
}

render() {
const displayZipCodes = this.state.zipCodes.map(item => (
<div>
{item}
</div>
));

return (
<div className="main">
<form>
<input
className="searchBox"
type="text"
name="query"
placeholder="Enter a city name"
value={this.state.query}
onChange={this.handleSubmit}
/>
<div className="buttonBox">
<button onClick={this.handleSearch}>Search</button>
</div>
</form>
{displayZipCodes}
</div>
);
}
}

export default SearchQuery;
53 changes: 53 additions & 0 deletions zip-search/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}


.main {
display: flex;
flex-flow: column;
align-items: center;
}

header {
background-color: #222;
color: white;
display: flex;
flex-flow: row;
justify-content: center;
height: 20vh;
font-size: 2em;
}

.searchBox {
margin-top: 4rem;
padding: 1rem;
height: 0.01rem;
min-width: 40vw;
border: 1px solid #a1a8a2;
}


.results {
font-size: 1.5rem;
width: 80vw;
background: #fff;
padding: 10px;
text-align: center;
word-wrap: break-word;
}

a {
color: inherit;
text-decoration: none;
}
10 changes: 8 additions & 2 deletions zip-search/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

const rootElement = document.getElementById("root");
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
</React.StrictMode>, rootElement
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
1 change: 1 addition & 0 deletions zip-search/src/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions zip-search/src/reportWebVitals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const reportWebVitals = onPerfEntry => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};

export default reportWebVitals;
5 changes: 5 additions & 0 deletions zip-search/src/setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
23 changes: 23 additions & 0 deletions zipcodesearch/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
70 changes: 70 additions & 0 deletions zipcodesearch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
Loading