-
Notifications
You must be signed in to change notification settings - Fork 36
Redux Eval #26
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
martinsalinas0
wants to merge
24
commits into
projectshft:main
Choose a base branch
from
martinsalinas0: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
Redux Eval #26
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
ac91567
init commit
martinsalinas0 4258221
add: fetchFiveDay component
martinsalinas0 a678596
remove: table.jsx
martinsalinas0 eb98fef
add: axios dependency
martinsalinas0 47d06a3
add: fetchFiveDay component
martinsalinas0 a34934f
add: chartCard component
martinsalinas0 290b3a3
update:
martinsalinas0 5fce9f6
update
martinsalinas0 9ada2e7
added: store files and folders
martinsalinas0 feae4dd
add: forecastSlice.js
martinsalinas0 b5d2337
fix: forecastSlice.js
martinsalinas0 8d96db4
add: confugureStore,js
martinsalinas0 de25f8c
add: forecastSlice.js
martinsalinas0 fe9400f
Merge branch 'main' of https://github.com/martinsalinas0/rtk-weather
martinsalinas0 f9cf8f0
update: update forecastSlice.js
martinsalinas0 ba45361
update: ChartCard.jsx
martinsalinas0 4f2c180
update ChartCard
martinsalinas0 68b0b4b
update: cityview.jsx
martinsalinas0 2386e58
update: forecastSlice.js
martinsalinas0 c6cf4b4
update: configureStore.js
martinsalinas0 7a63715
update: forecastSlice.js
martinsalinas0 30e3bf5
update: cityView.js
martinsalinas0 4b337fd
updates
martinsalinas0 5cc6c26
updateas
martinsalinas0 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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "workbench.colorCustomizations": { | ||
| "activityBar.activeBackground": "#2f7c47", | ||
| "activityBar.background": "#2f7c47", | ||
| "activityBar.foreground": "#e7e7e7", | ||
| "activityBar.inactiveForeground": "#e7e7e799", | ||
| "activityBarBadge.background": "#422c74", | ||
| "activityBarBadge.foreground": "#e7e7e7", | ||
| "commandCenter.border": "#e7e7e799", | ||
| "sash.hoverBorder": "#2f7c47", | ||
| "statusBar.background": "#215732", | ||
| "statusBar.foreground": "#e7e7e7", | ||
| "statusBarItem.hoverBackground": "#2f7c47", | ||
| "statusBarItem.remoteBackground": "#215732", | ||
| "statusBarItem.remoteForeground": "#e7e7e7", | ||
| "titleBar.activeBackground": "#215732", | ||
| "titleBar.activeForeground": "#e7e7e7", | ||
| "titleBar.inactiveBackground": "#21573299", | ||
| "titleBar.inactiveForeground": "#e7e7e799" | ||
| }, | ||
| "peacock.color": "#215732" | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| "use client"; | ||
| import { useEffect, useState } from "react"; | ||
| import { useDispatch, useSelector } from "react-redux"; | ||
| import { | ||
| deleteCity, | ||
| fetchForecast, | ||
| resetList, | ||
| } from "@/store/slices/forecastSlice"; | ||
|
|
||
| import { | ||
| Sparklines, | ||
| SparklinesLine, | ||
| SparklinesReferenceLine, | ||
| } from "react-sparklines"; | ||
|
|
||
| export default function CityView() { | ||
| const { forecastData, loading, error, cities } = useSelector( | ||
| (state) => state.forecast | ||
| ); | ||
|
|
||
| const dispatch = useDispatch(); | ||
|
|
||
| const [query, setQuery] = useState(""); | ||
|
|
||
| useEffect(() => {}, []); | ||
|
|
||
| const handleSearch = () => { | ||
| if (!query || query.trim() === "") { | ||
| alert("Search cannot be empty"); | ||
| setQuery(""); | ||
| } else { | ||
| dispatch(fetchForecast(query)); | ||
| setQuery(""); | ||
| } | ||
| }; | ||
|
|
||
| const handleReset = () => { | ||
| if (confirm("Are you sure you want to reset? ")) { | ||
| dispatch(resetList()); | ||
| } | ||
| }; | ||
|
|
||
| const handleInput = (event) => { | ||
| setQuery(event.target.value); | ||
| }; | ||
|
|
||
| const handleDelete = (cityId) => { | ||
| if (confirm("are you sure you want to delete this city?")) { | ||
| dispatch(deleteCity(cityId)); | ||
| } | ||
| }; | ||
|
|
||
| function average(arr) { | ||
|
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. very generic function name and argument, be specific |
||
| return arr.reduce((sum, num) => sum + num) / arr.length; | ||
| } | ||
|
|
||
| return ( | ||
| <div className="container"> | ||
| <div className="input-group m-5"> | ||
| <input | ||
| type="text" | ||
| className="form-control" | ||
| placeholder="Search city" | ||
| value={query} | ||
| onChange={handleInput} | ||
| required | ||
| /> | ||
| <button | ||
| type="button" | ||
| className="btn btn-primary" | ||
| onClick={handleSearch} | ||
| > | ||
| Search | ||
| </button> | ||
| </div> | ||
| <div className="container"> | ||
| <div className=" text-center"> | ||
| <button | ||
| type="button" | ||
| className="btn btn-danger btn-sm" | ||
| onClick={handleReset} | ||
| > | ||
| {" "} | ||
| reset list | ||
| </button> | ||
|
|
||
| </div> | ||
| </div> | ||
|
|
||
| <h2 className="text-center m-4">City Forecast</h2> | ||
| {loading && <div>Loading...</div>} | ||
| {!loading && error && <div>Error: {error}</div>} | ||
| {!loading && forecastData && ( | ||
| <div> | ||
| <table className="table"> | ||
| <thead> | ||
| <tr> | ||
| <th scope="col"></th> | ||
| <th scope="col">City</th> | ||
| <th scope="col">Temperature (°F)</th> | ||
| <th scope="col">Humidity (%)</th> | ||
| <th scope="col">Pressure (hPa)</th> | ||
| <th scope="col">Actions</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {cities.map((city) => { | ||
| const tempArray = city.list.map((item) => item.main.temp); | ||
| const humidityArray = city.list.map( | ||
| (item) => item.main.humidity | ||
| ); | ||
| const pressureArray = city.list.map( | ||
| (item) => item.main.pressure | ||
| ); | ||
|
|
||
| const tempAvg = Math.round(average(tempArray)); | ||
| const humidAvg = Math.round(average(humidityArray)); | ||
| const pressAvg = Math.round(average(pressureArray)); | ||
|
|
||
| return ( | ||
| <tr key={city.id} className="align-bottom"> | ||
| <td scope="row" className="align-middle"></td> | ||
| <td className="align-middle"> | ||
| <h2>{city.name}</h2> | ||
| </td> | ||
| <td className="align-bottom"> | ||
| <Sparklines data={tempArray} height={75} width={125}> | ||
| <SparklinesLine color="red" /> | ||
| <SparklinesReferenceLine type="mean" /> | ||
| </Sparklines> | ||
| <div className="text-center"> | ||
| {" "} | ||
| <h5>{tempAvg} °F </h5> | ||
| </div> | ||
| </td> | ||
| <td className="align-bottom"> | ||
| <Sparklines data={humidityArray} height={75} width={125}> | ||
| <SparklinesLine color="green" /> | ||
| <SparklinesReferenceLine type="mean" /> | ||
| </Sparklines> | ||
| <div className="text-center"> | ||
| {" "} | ||
| <h5>{humidAvg} %</h5> | ||
| </div> | ||
| </td> | ||
| <td className="align-bottom"> | ||
| <Sparklines data={pressureArray} height={75} width={125}> | ||
| <SparklinesLine color="blue" /> | ||
| <SparklinesReferenceLine type="mean" /> | ||
| </Sparklines> | ||
| <div className="text-center"> | ||
| <h5>{pressAvg} hPa </h5> | ||
| </div> | ||
| </td> | ||
| <td className="text-center align-middle"> | ||
| <button | ||
| onClick={() => handleDelete(city.id)} | ||
| className="btn btn-danger btn-sm" | ||
| > | ||
| Delete | ||
| </button> | ||
| </td> | ||
| </tr> | ||
| ); | ||
| })} | ||
| </tbody> | ||
| </table> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
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 +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; | ||
| } | ||
| } | ||
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,20 @@ | ||
| import './globals.css' | ||
| import { Inter } from 'next/font/google' | ||
| "use client"; | ||
| import "bootstrap/dist/css/bootstrap.css"; | ||
| import { Signika_Negative } from "next/font/google"; | ||
| import { Provider } from "react-redux"; | ||
| import store from "@/store/configureStore"; | ||
|
|
||
| const inter = Inter({ subsets: ['latin'] }) | ||
|
|
||
| export const metadata = { | ||
| title: 'Create Next App', | ||
| description: 'Generated by create next app', | ||
| } | ||
| const signikaNegative = Signika_Negative({ | ||
| subsets: ["latin"], | ||
| weight: ["400", "500", "700"], | ||
| }); | ||
|
|
||
| export default function RootLayout({ children }) { | ||
| return ( | ||
| <html lang="en"> | ||
| <body className={inter.className}>{children}</body> | ||
| <body className={signikaNegative.className}> | ||
| <Provider store={store}>{children}</Provider> | ||
| </body> | ||
| </html> | ||
| ) | ||
| ); | ||
| } |
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.
DRY
create a function resetSearchBox that calls setQuery. Will help with readability also.