-
Notifications
You must be signed in to change notification settings - Fork 36
initial commit #8
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
Open
nsLittle
wants to merge
4
commits into
projectshft:main
Choose a base branch
from
nsLittle:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,39 @@ | ||
| ## Weather Project | ||
|
|
||
| This project has been created by a student at Parsity, an online software engineering course. The work in this repository is wholly of the student based on a sample starter project that can be accessed by looking at the repository that this project forks. | ||
| This project was created by Mutsumi Hata, a student at Parsity, an online software engineering program. The work in this repository is wholly of the student based on a sample starter project that can be accessed by looking at the original repository from which this project forks. | ||
|
|
||
| If you have any questions about this project or the program in general, visit [parsity.io](https://parsity.io/) or email hello@parsity.io. | ||
|
|
||
| ### Project Description | ||
|
|
||
| This simple Redux application builds upon my knowledge of React. I used React's ability to manage components in separate, and more manageble files. I then added Redux's ability to make state management more predictable and scalable. This application also uses React's Sparkline feature to create a line graph of the 5-day temperature, air pressure, and humidity forecasts. | ||
|
|
||
| The application allows a user to input the name of a city and returns a 5-day forecast for temperatutre, air pressure and humidity. Along with the daily average, the application returns a 5-day average, along with a line graph of the returned data. | ||
|
|
||
| I would like to become more familiar with customizing SparkLine charts. | ||
|
|
||
| ### Table of Contents | ||
|
|
||
| RTK-Weather | ||
|
|
||
| - store | ||
| - slices | ||
| - search.js | ||
| - configureStore.js | ||
| - rootReducer.js | ||
| - globals.css | ||
| - layout.js | ||
| - page.js | ||
| - README.md | ||
|
|
||
| ### How to Run Application | ||
|
|
||
| 1. Open terminal | ||
| 2. Locate file: rtk-weather | ||
| 3. Type: npm run dev | ||
| 4. Type: open http://localhost:3000 (or other appropriate host) | ||
|
|
||
| ### Things to Add/Edit | ||
|
|
||
| 1. Clear input field onClick | ||
| 2. Cleaner visual - each city result should be on one line |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,107 +1,3 @@ | ||
| :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; | ||
| } | ||
| background-color: white; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| 'use client'; | ||
| import React from 'react'; | ||
| import { Provider } from 'react-redux'; | ||
| import store from './store/configureStore'; | ||
| 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', | ||
| } | ||
|
|
||
| export default function RootLayout({ children }) { | ||
| return ( | ||
| <html lang="en"> | ||
| <body className={inter.className}>{children}</body> | ||
| <body> | ||
| <Provider store={store}> | ||
| {children} | ||
| </Provider> | ||
| </body> | ||
| </html> | ||
| ) | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,95 +1,106 @@ | ||
| import Image from 'next/image' | ||
| import styles from './page.module.css' | ||
| 'use client'; | ||
| import React, { useState } from 'react'; | ||
| import { useDispatch } from 'react-redux'; | ||
| import { Sparklines, SparklinesLine } from 'react-sparklines'; | ||
| import { fetchWeather } from './store/slices/search'; | ||
|
|
||
| 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> | ||
| const [searchInput, setSearchInput] = useState(''); | ||
| const [searchResults, setSearchResults] = useState([]); | ||
| const dispatch = useDispatch(); | ||
|
|
||
| <div className={styles.center}> | ||
| <Image | ||
| className={styles.logo} | ||
| src="/next.svg" | ||
| alt="Next.js Logo" | ||
| width={180} | ||
| height={37} | ||
| priority | ||
| /> | ||
| </div> | ||
| const handleSearch = () => { | ||
| if (searchInput.trim() === ''){ | ||
| alert('Error! You must enter a city name.'); | ||
| return; | ||
| } | ||
|
|
||
| <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> | ||
| dispatch(fetchWeather(searchInput)) | ||
| .then((response) => { | ||
| if (response.payload.cod === '404') { | ||
| alert('Error! You did not enter a correctly spelled city.'); | ||
| } else { | ||
| setSearchResults((prevResults) => [ | ||
| ...prevResults, | ||
| { city: searchInput, data: response.payload } | ||
| ]); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| <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> | ||
| const calculateAverage = (dataList, property) => { | ||
| if (!dataList || dataList.length === 0) return 0; | ||
| const sum = dataList.reduce((acc, item) => acc + item.main[property], 0); | ||
| return (sum / dataList.length).toFixed(2); | ||
| }; | ||
|
|
||
| return ( | ||
| <main> | ||
| <h1>Sparkly Sparkles Weather</h1> | ||
| <input id="search-query" placeholder='Enter city name' onChange={(e) => setSearchInput(e.target.value)} /> | ||
| <br /> | ||
| <button onClick={handleSearch}>Search</button> | ||
|
|
||
| <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> | ||
| {searchResults.map((result, index) => ( | ||
| <div key={index}> | ||
| <h2 className='other-data'>{result.city}</h2> | ||
|
|
||
| <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> | ||
| {result.data && result.data.list && result.data.list.length > 0 && ( | ||
| <> | ||
| <h3>Temperature</h3> | ||
| <div style={{ width: '300px', height: '125px', padding: '0', margin: '0' }}> | ||
| <Sparklines data={result.data.list.slice(0, 5).map(datum => datum.main.temp)} height={50}> | ||
| <SparklinesLine color="#FFA500" /> | ||
| </Sparklines> | ||
| </div> | ||
| <div className='search-results-five'> | ||
| <ul> | ||
| {result.data.list.slice(0, 5).map((datum, index) => ( | ||
| <li key={index} className='data'>{datum.main && datum.main.temp}</li> | ||
| ))} | ||
| </ul> | ||
| <ul> | ||
| <li className='data'>5-day average: {calculateAverage(result.data.list, 'temp')}</li> | ||
| </ul> | ||
| </div> | ||
|
|
||
| <h3>Pressure</h3> | ||
| <div style={{ width: '300px', height: '125px', padding: '0', margin: '0' }}> | ||
| <Sparklines data={result.data.list.slice(0, 5).map(item => item.main.pressure)} height={50}> | ||
| <SparklinesLine color="#000080" /> | ||
| </Sparklines> | ||
| </div> | ||
| <div className='search-results-five'> | ||
| <ul> | ||
| {result.data.list.slice(0, 5).map((item, index) => ( | ||
| <li key={index} className='data'>{item.main && item.main.pressure}</li> | ||
| ))} | ||
| </ul> | ||
| <ul> | ||
| <li className='data'>5-day average: {calculateAverage(result.data.list, 'pressure')}</li> | ||
| </ul> | ||
| </div> | ||
|
|
||
| <h3>Humidity</h3> | ||
| <div style={{ width: '300px', height: '125px', padding: '0', margin: '0' }}> | ||
| <Sparklines data={result.data.list.slice(0, 5).map(item => item.main.humidity)} height={50}> | ||
| <SparklinesLine color="#008000" /> | ||
| </Sparklines> | ||
| </div> | ||
| <div className='search-results-five'> | ||
| <ul> | ||
| {result.data.list.slice(0, 5).map((item, index) => ( | ||
| <li key={index} className='data'>{item.main && item.main.humidity}</li> | ||
| ))} | ||
| </ul> | ||
| <ul> | ||
| <li className='data'>5-day average: {calculateAverage(result.data.list, 'humidity')}</li> | ||
| </ul> | ||
|
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. this html is a bit long and hard to understand, there's logic also that could have been extracted to functions to help with readability |
||
| </div> | ||
| </> | ||
| )} | ||
| </div> | ||
| ))} | ||
| </main> | ||
| ) | ||
| } | ||
| ); | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
interesting that the interface is .cod and not .code