-
Notifications
You must be signed in to change notification settings - Fork 36
Michael Wagner Weather Eval #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ab5d790
69d800c
11b4f18
2512819
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| 'use client'; | ||
| import { useState } from 'react'; | ||
| import { useDispatch } from 'react-redux'; | ||
| import { fetchWeather } from '../store/slices/cities'; | ||
|
|
||
| export default function CitySearch() { | ||
| //setting up useState and Dispatch | ||
| const dispatch = useDispatch(); | ||
| const [city, setCity] = useState(''); | ||
| //submit button function that requests API and formats API and sets useState back to '' | ||
| const handleFormSubmit = (event) => { | ||
| event.preventDefault(); | ||
| dispatch(fetchWeather(city)); | ||
| setCity(''); | ||
| }; | ||
| //UI for the Submit form area with submit button | ||
| return ( | ||
| <form onSubmit={handleFormSubmit}> | ||
| <div className='col-6 offset-3'> | ||
| <label>Enter City Name</label> | ||
| <input | ||
| className='form-control' | ||
| value={city} | ||
| onChange={(event) => setCity(event.target.value)} | ||
| ></input> | ||
| <br /> | ||
| <button className='btn btn-primary' type='submit'> | ||
| Submit | ||
| </button> | ||
| </div> | ||
| </form> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| 'use client'; | ||
| import React from 'react'; | ||
| import { useSelector } from 'react-redux'; | ||
| import { | ||
| Sparklines, | ||
| SparklinesReferenceLine, | ||
| SparklinesLine, | ||
| SparklinesCurve, | ||
| } from 'react-sparklines'; | ||
|
|
||
| export default function CityWeather() { | ||
| const cities = useSelector((state) => state.cities.cities); | ||
| //function to get averages of weather data | ||
| const getAverage = (array) => | ||
| Math.round( | ||
| array.reduce((sum, currentValue) => sum + currentValue, 0) / | ||
| array.length | ||
| ); | ||
| //displays cities weather with charts if they have been passed in. Has averages below each chart. If no info displays no weather data | ||
| const renderCities = () => { | ||
| if (cities.length > 0) { | ||
| return cities.map((city, index) => { | ||
| return ( | ||
| <tbody key={index}> | ||
| <tr> | ||
| <th scope='row'>{city.cityName}</th> | ||
| <td> | ||
| <Sparklines data={city.temp}> | ||
| <SparklinesLine color='blue' /> | ||
| <SparklinesReferenceLine type='avg' /> | ||
| </Sparklines> | ||
| </td> | ||
| <td> | ||
| <Sparklines data={city.pressure}> | ||
| <SparklinesLine color='red' /> | ||
| <SparklinesReferenceLine type='avg' /> | ||
| </Sparklines> | ||
| </td> | ||
| <td> | ||
| <Sparklines data={city.humidity}> | ||
| <SparklinesLine color='yellow' /> | ||
| <SparklinesReferenceLine type='avg' /> | ||
| </Sparklines> | ||
| </td> | ||
|
Comment on lines
+27
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DRY, don't repeat yourself, use JS helpers and components to make it more readable |
||
| </tr> | ||
| <tr> | ||
| <th></th> | ||
| <td>{getAverage(city.temp)}(F)</td> | ||
| <td>{getAverage(city.pressure)}(hPa)</td> | ||
| <td>{getAverage(city.humidity)}(%)</td> | ||
| </tr> | ||
| </tbody> | ||
| ); | ||
| }); | ||
| } else { | ||
| return <div>No Weather Data To Show</div>; | ||
| } | ||
| }; | ||
|
|
||
| //ui for the City Weather section of the app. Displayed in table format | ||
| return ( | ||
| <table className='table'> | ||
| <thead> | ||
| <tr className='text-bold'> | ||
| <th scope='col'>City</th> | ||
| <th scope='col'>Temperature(F)</th> | ||
| <th scope='col'>Pressure(hPa)</th> | ||
| <th scope='col'>Humidity(%)</th> | ||
| </tr> | ||
| </thead> | ||
| {renderCities()} | ||
| </table> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,107 +0,0 @@ | ||
| :root { | ||
| --max-width: 1100px; | ||
| --border-radius: 12px; | ||
| --font-mono: ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', | ||
| 'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro', | ||
| 'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace; | ||
|
|
||
| --foreground-rgb: 0, 0, 0; | ||
| --background-start-rgb: 214, 219, 220; | ||
| --background-end-rgb: 255, 255, 255; | ||
|
|
||
| --primary-glow: conic-gradient( | ||
| from 180deg at 50% 50%, | ||
| #16abff33 0deg, | ||
| #0885ff33 55deg, | ||
| #54d6ff33 120deg, | ||
| #0071ff33 160deg, | ||
| transparent 360deg | ||
| ); | ||
| --secondary-glow: radial-gradient( | ||
| rgba(255, 255, 255, 1), | ||
| rgba(255, 255, 255, 0) | ||
| ); | ||
|
|
||
| --tile-start-rgb: 239, 245, 249; | ||
| --tile-end-rgb: 228, 232, 233; | ||
| --tile-border: conic-gradient( | ||
| #00000080, | ||
| #00000040, | ||
| #00000030, | ||
| #00000020, | ||
| #00000010, | ||
| #00000010, | ||
| #00000080 | ||
| ); | ||
|
|
||
| --callout-rgb: 238, 240, 241; | ||
| --callout-border-rgb: 172, 175, 176; | ||
| --card-rgb: 180, 185, 188; | ||
| --card-border-rgb: 131, 134, 135; | ||
| } | ||
|
|
||
| @media (prefers-color-scheme: dark) { | ||
| :root { | ||
| --foreground-rgb: 255, 255, 255; | ||
| --background-start-rgb: 0, 0, 0; | ||
| --background-end-rgb: 0, 0, 0; | ||
|
|
||
| --primary-glow: radial-gradient(rgba(1, 65, 255, 0.4), rgba(1, 65, 255, 0)); | ||
| --secondary-glow: linear-gradient( | ||
| to bottom right, | ||
| rgba(1, 65, 255, 0), | ||
| rgba(1, 65, 255, 0), | ||
| rgba(1, 65, 255, 0.3) | ||
| ); | ||
|
|
||
| --tile-start-rgb: 2, 13, 46; | ||
| --tile-end-rgb: 2, 5, 19; | ||
| --tile-border: conic-gradient( | ||
| #ffffff80, | ||
| #ffffff40, | ||
| #ffffff30, | ||
| #ffffff20, | ||
| #ffffff10, | ||
| #ffffff10, | ||
| #ffffff80 | ||
| ); | ||
|
|
||
| --callout-rgb: 20, 20, 20; | ||
| --callout-border-rgb: 108, 108, 108; | ||
| --card-rgb: 100, 100, 100; | ||
| --card-border-rgb: 200, 200, 200; | ||
| } | ||
| } | ||
|
|
||
| * { | ||
| box-sizing: border-box; | ||
| padding: 0; | ||
| margin: 0; | ||
| } | ||
|
|
||
| html, | ||
| body { | ||
| max-width: 100vw; | ||
| overflow-x: hidden; | ||
| } | ||
|
|
||
| body { | ||
| color: rgb(var(--foreground-rgb)); | ||
| background: linear-gradient( | ||
| to bottom, | ||
| transparent, | ||
| rgb(var(--background-end-rgb)) | ||
| ) | ||
| rgb(var(--background-start-rgb)); | ||
| } | ||
|
|
||
| a { | ||
| color: inherit; | ||
| text-decoration: none; | ||
| } | ||
|
|
||
| @media (prefers-color-scheme: dark) { | ||
| html { | ||
| color-scheme: dark; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| import './globals.css' | ||
| import { Inter } from 'next/font/google' | ||
|
|
||
| const inter = Inter({ subsets: ['latin'] }) | ||
|
|
||
| export const metadata = { | ||
| title: 'Create Next App', | ||
| description: 'Generated by create next app', | ||
| } | ||
|
|
||
| 'use client'; | ||
| import './globals.css'; | ||
| import { Inter } from 'next/font/google'; | ||
| import { Provider } from 'react-redux'; | ||
| import 'bootstrap/dist/css/bootstrap.css'; | ||
| import store from './store/configureStore'; | ||
| const inter = Inter({ subsets: ['latin'] }); | ||
| //boilerplate | ||
| export default function RootLayout({ children }) { | ||
| return ( | ||
| <html lang="en"> | ||
| <body className={inter.className}>{children}</body> | ||
| </html> | ||
| ) | ||
| return ( | ||
| <html lang='en'> | ||
| <body className={inter.className}> | ||
| <Provider store={store}>{children}</Provider> | ||
| </body> | ||
| </html> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,95 +1,21 @@ | ||
| import Image from 'next/image' | ||
| import styles from './page.module.css' | ||
| import CitySearch from './components/citySearch'; | ||
| import CityWeather from './components/cityWeather'; | ||
|
|
||
| //ui for application | ||
| export default function Home() { | ||
| return ( | ||
| <main className={styles.main}> | ||
| <div className={styles.description}> | ||
| <p> | ||
| Get started by editing | ||
| <code className={styles.code}>app/page.js</code> | ||
| </p> | ||
| <div> | ||
| <a | ||
| href="https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| > | ||
| By{' '} | ||
| <Image | ||
| src="/vercel.svg" | ||
| alt="Vercel Logo" | ||
| className={styles.vercelLogo} | ||
| width={100} | ||
| height={24} | ||
| priority | ||
| /> | ||
| </a> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className={styles.center}> | ||
| <Image | ||
| className={styles.logo} | ||
| src="/next.svg" | ||
| alt="Next.js Logo" | ||
| width={180} | ||
| height={37} | ||
| priority | ||
| /> | ||
| </div> | ||
|
|
||
| <div className={styles.grid}> | ||
| <a | ||
| href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app" | ||
| className={styles.card} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| > | ||
| <h2> | ||
| Docs <span>-></span> | ||
| </h2> | ||
| <p>Find in-depth information about Next.js features and API.</p> | ||
| </a> | ||
|
|
||
| <a | ||
| href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app" | ||
| className={styles.card} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| > | ||
| <h2> | ||
| Learn <span>-></span> | ||
| </h2> | ||
| <p>Learn about Next.js in an interactive course with quizzes!</p> | ||
| </a> | ||
|
|
||
| <a | ||
| href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app" | ||
| className={styles.card} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| > | ||
| <h2> | ||
| Templates <span>-></span> | ||
| </h2> | ||
| <p>Explore the Next.js 13 playground.</p> | ||
| </a> | ||
|
|
||
| <a | ||
| href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app" | ||
| className={styles.card} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| > | ||
| <h2> | ||
| Deploy <span>-></span> | ||
| </h2> | ||
| <p> | ||
| Instantly deploy your Next.js site to a shareable URL with Vercel. | ||
| </p> | ||
| </a> | ||
| </div> | ||
| </main> | ||
| ) | ||
| return ( | ||
| <body> | ||
| <div className='text-center'> | ||
| <h1>Weather App</h1> | ||
| </div> | ||
| <br /> | ||
| <br /> | ||
|
Comment on lines
+11
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its not a good practice to use breaks for design purposes. Next time use css |
||
| <div className='text-center'> | ||
| <CitySearch /> | ||
| <br /> | ||
| <br /> | ||
| <CityWeather /> | ||
| </div> | ||
| </body> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { configureStore } from '@reduxjs/toolkit'; | ||
| import rootReducer from './rootReducer'; | ||
|
|
||
| const store = configureStore({ | ||
| reducer: rootReducer, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check your code alignment |
||
| }); | ||
|
|
||
| export default store; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { combineReducers } from 'redux'; | ||
| import citiesReducer from './slices/cities'; | ||
|
|
||
| const rootReducer = combineReducers({ | ||
| cities: citiesReducer, | ||
| }); | ||
|
|
||
| export default rootReducer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its a better UX to clear the input only after the call is successful. If the user enters a bad input, you want to see it and not clear it