-
Notifications
You must be signed in to change notification settings - Fork 36
Eval Submission Thanh Nguyen #16
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
colormethanh
wants to merge
18
commits into
projectshft:main
Choose a base branch
from
colormethanh: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
18 commits
Select commit
Hold shift + click to select a range
8895e33
set up api calls
colormethanh 66bfeb4
added search result validation
colormethanh b76f9a2
Added current weather population
colormethanh 9207831
Fixed enter key not submitting bug
colormethanh 668aad7
set up graph example
colormethanh 60d5f59
added fiive day weather dropdown
colormethanh 1c379ae
refactored props in weatherPanel
colormethanh bca421e
added graphs
colormethanh a0efc91
fixed graph data
colormethanh 5b365d2
added more validation
colormethanh 9082a01
seperated form from search bar
colormethanh a92fc4f
added default location. Need to fix double render bug
colormethanh ab9bbf3
re-factored default location
colormethanh 2f59e1d
Fixed double load of default weather data
colormethanh c208d7d
refactored code
colormethanh 19fd7ac
debugged the refactor
colormethanh 931a399
Finished project
colormethanh 77bfa37
Edited README
colormethanh 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,9 @@ | ||
| { | ||
| "cSpell.words": [ | ||
| "accum", | ||
| "APIKEY", | ||
| "hookform", | ||
| "openweathermap", | ||
| "Sparklines" | ||
| ] | ||
| } |
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
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,67 @@ | ||
| "use client" | ||
| import { useDispatch, useSelector } from "react-redux"; | ||
| import { setCurrentLocation } from "../store/slices/locations"; | ||
| import { getWeather } from "./WeatherAPI"; | ||
|
|
||
| export default function AppNavbar() { | ||
| const dispatch = useDispatch(); | ||
| const defaultLocation = useSelector(state => state.locations.defaultLocation); | ||
|
|
||
| const onSuccess = async (data) => { | ||
| try { | ||
| if (!data) return | ||
| const { latitude, longitude } = data.coords; | ||
| const weatherData = await getWeather("", {lat : latitude, lon: longitude}) | ||
| dispatch(setCurrentLocation(weatherData)); | ||
| } catch (e) { | ||
| console.log(e); | ||
| } | ||
| }; | ||
|
|
||
| const onError = (error) => { | ||
| console.log(error) | ||
| }; | ||
|
|
||
| const handleSetLocation = (navigator, onSuccess, onError) => { | ||
| const geolocation = navigator.geolocation; | ||
| if (!geolocation) return alert("Geolocation is not supported. Sorry!"); | ||
|
|
||
| geolocation.getCurrentPosition(onSuccess, onError, {enableHighAccuracy:true}); | ||
| }; | ||
|
|
||
| return ( | ||
| <nav | ||
| className="navbar navbar-expand-lg navbar-light bg-light navbar-brand-center mb-3" | ||
| > | ||
| <a className="navbar-brand ms-3" href="#">RTK Weather</a> | ||
| <ul className="navbar-nav mx-auto"> | ||
| <li className="nav-item navbar-text" id="default-city-text"> | ||
| Default location: {defaultLocation ? defaultLocation.name : "Not Set"} | ||
| </li> | ||
| </ul> | ||
| <a | ||
| className="nav-link me-3 btn btn-primary" | ||
| type="button" | ||
| id="cur-loc-btn" | ||
| href="#" | ||
| onClick={() => handleSetLocation(navigator, onSuccess, onError)} | ||
| > | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| width="16" | ||
| height="16" | ||
| fill="currentColor" | ||
| className="bi bi-geo-alt" | ||
| viewBox="0 0 16 16" | ||
| > | ||
| <path | ||
| d="M12.166 8.94c-.524 1.062-1.234 2.12-1.96 3.07A32 32 0 0 1 8 14.58a32 32 0 0 1-2.206-2.57c-.726-.95-1.436-2.008-1.96-3.07C3.304 7.867 3 6.862 3 6a5 5 0 0 1 10 0c0 .862-.305 1.867-.834 2.94M8 16s6-5.686 6-10A6 6 0 0 0 2 6c0 4.314 6 10 6 10" | ||
| /> | ||
| <path | ||
| d="M8 8a2 2 0 1 1 0-4 2 2 0 0 1 0 4m0 1a3 3 0 1 0 0-6 3 3 0 0 0 0 6" | ||
| /> | ||
| </svg> | ||
| </a> | ||
| </nav> | ||
| ) | ||
| } |
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,15 @@ | ||
| "use client"; | ||
|
|
||
| import { useEffect } from "react"; | ||
|
|
||
| function BootstrapClient() { | ||
| useEffect(() => { | ||
| require('bootstrap/dist/js/bootstrap.bundle.min.js'); | ||
| }, []); | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| export default BootstrapClient; | ||
|
|
||
|
|
||
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 @@ | ||
| import Image from "next/image"; | ||
|
|
||
| export default function CurrentWeather({ currentWeatherDetails }) { | ||
|
|
||
| return ( | ||
| <div className="d-flex justify-content-around text-center"> | ||
| <div className="cur-weather-text d-flex flex-column justify-content-center"> | ||
| <div className="weather-degree">{currentWeatherDetails.temp}°</div> | ||
| <div className="weather-city">{currentWeatherDetails.name}</div> | ||
| <div className="weather-condition">{currentWeatherDetails.weather}</div> | ||
| </div> | ||
| <Image | ||
| src={`https://openweathermap.org/img/wn/${currentWeatherDetails.iconCode}@2x.png`} | ||
| alt={`${currentWeatherDetails.weather} icon`} | ||
| width={100} | ||
| height={100} | ||
| priority | ||
| className="cur-weather-icon" | ||
| /> | ||
| </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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import Image from "next/image"; | ||
| import {v4 as uuidv4} from "uuid"; | ||
| import { useEffect, useState } from "react"; | ||
|
|
||
| export default function DayBox({ day }) { | ||
| const [width, setWidth] = useState(window.innerWidth); | ||
|
|
||
| useEffect(() => { | ||
| const handleResize = () => { | ||
| setWidth(window.innerWidth); | ||
| }; | ||
|
|
||
| window.addEventListener('resize', handleResize); | ||
|
|
||
| return () => { | ||
| window.removeEventListener('resize', handleResize); | ||
| }; | ||
| }, []); | ||
|
|
||
|
|
||
| return ( | ||
| <div key={uuidv4()} className={`five-day-box col d-flex flex-column align-items-center justify-content-between ${width <= 763 && "border-bottom"} `}> | ||
| <div className="weather-condition-sm">{day.weather}</div> | ||
| <div className="weather-degree-sm">{day.temp}°</div> | ||
| <Image | ||
| src={`https://openweathermap.org/img/wn/${day.iconCode}@2x.png`} | ||
| alt={`${day.weather} icon`} | ||
| className="cur-weather-icon" | ||
| width={50} height={50} | ||
| /> | ||
| <div className="weather-day">{day.day}</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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
|
|
||
| export default function Error({message }) { | ||
| return ( | ||
| <div className="text-danger"> | ||
| <p>Error: {message}</p> | ||
| </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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import {v4 as uuidv4} from "uuid"; | ||
| import DayBox from "./DayBox"; | ||
|
|
||
| export default function FiveDayWeather({ fiveDayWeather }) { | ||
|
|
||
| return ( | ||
| <div className="five-day-panel row flex-column flex-md-row text-center"> | ||
| { fiveDayWeather.map(day => | ||
| <DayBox key={uuidv4()} day={day} />) | ||
| } | ||
| </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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { v4 as uuidv4 } from "uuid"; | ||
| import { Sparklines, SparklinesLine, SparklinesReferenceLine } from "react-sparklines"; | ||
|
|
||
| export default function Graph({ data, name }) { | ||
| // calculate the rounded average of the values array | ||
| const average = data.reduce((sum, cur) => sum + cur, 0) / data.length; | ||
| const roundedAverage = Math.ceil(average * 100) / 100; | ||
|
|
||
| return ( | ||
| <div className="col-xs-12 col-sm-4 d-flex flex-column" key={uuidv4()}> | ||
| {name.toUpperCase()} | ||
| <Sparklines data={data}> | ||
| <SparklinesLine color="blue" /> | ||
| <SparklinesReferenceLine type="avg" /> | ||
| </Sparklines> | ||
| <span> Avg: {roundedAverage} </span> | ||
| </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 |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { v4 as uuidv4 } from "uuid"; | ||
| import Graph from "./Graph"; | ||
|
|
||
| export default function Graphs ({ fiveDayWeather }) { | ||
| // Reduce five day weather to an object {temp: [], humidity:[], pressure:[]}. | ||
| const graphData = fiveDayWeather.reduce((accum, day) => { | ||
| accum.temp ? accum.temp.push(day.temp) : accum.temp = [day.temp]; | ||
| accum.humidity ? accum.humidity.push(day.humidity) : accum.humidity = [day.humidity]; | ||
| accum.pressure ? accum.pressure.push(day.pressure) : accum.pressure = [day.pressure]; | ||
| return accum; | ||
| }, {}); | ||
|
|
||
| return ( | ||
| <div className="five-day-panel row text-center"> | ||
| {Object.keys(graphData).map(key => | ||
| <Graph key={uuidv4()} data={graphData[key]} name={key} /> | ||
| )} | ||
| </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 |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { useState } from "react"; | ||
|
|
||
| export default function Modal ({action, text, title = "Modal", body= "", closeText = "Close", submitText="Save Changes"}) { | ||
| const [show, setShow] = useState(false); | ||
| const handleClose = () => setShow(false); | ||
| const handleShow = (e) => { | ||
| e.preventDefault() | ||
| setShow(true) | ||
| }; | ||
|
|
||
| const handleSubmit = (action) => { | ||
| console.log("Handling set default") | ||
| action(); | ||
| handleClose(); | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <a className="no-decorations" href="" onClick={(e) => {handleShow(e)}}> | ||
| {text} | ||
| </a> | ||
|
|
||
| {/* Modal */} | ||
| <div className={`modal fade ${show ? 'show d-block' : ''}`} tabIndex="-1" role="dialog"> | ||
| <div className="modal-dialog" role="document"> | ||
| <div className="modal-content"> | ||
| <div className="modal-header"> | ||
| <h5 className="modal-title">{title}</h5> | ||
| </div> | ||
| <div className="modal-body"> | ||
| <p>{body}</p> | ||
| </div> | ||
| <div className="modal-footer"> | ||
| <button type="button" className="btn btn-secondary" onClick={handleClose}> | ||
| {closeText} | ||
| </button> | ||
| <button type="button" className="btn btn-primary" onClick={() => {handleSubmit(action)}}> | ||
| {submitText} | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Background overlay for modal */} | ||
| {show && <div className="modal-backdrop fade show"></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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import Weather from "./Weather"; | ||
| import CurrentWeather from "./CurrentWeather"; | ||
|
|
||
| export default function Panel({ weatherDetails}) { | ||
|
|
||
| return ( | ||
| <div className="weather-panel row d-flex justify-content-center w-75 border"> | ||
| <CurrentWeather currentWeatherDetails={weatherDetails.currentWeather} /> | ||
| <Weather weatherDetails={weatherDetails} /> | ||
| </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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| "use client" | ||
| import { useState } from "react"; | ||
| import { getWeather } from "./WeatherAPI"; | ||
| import { useDispatch } from "react-redux"; | ||
| import { pushLocation } from "../store/slices/locations"; | ||
| import SearchBarForm from "./SearchBarForm"; | ||
| import useReturnDataValidation from "./useReturnDataValidation" | ||
|
|
||
| export default function SearchBar() { | ||
| const [searchErrors, setSearchErrors] = useState(null); | ||
| const dispatch = useDispatch(); | ||
|
|
||
| const weatherSchema = useReturnDataValidation() | ||
|
|
||
| const handleFormSubmit = async (inputText) => { | ||
| // Reset errors | ||
| setSearchErrors(null); | ||
|
|
||
| try { | ||
| // Get location based on city name | ||
| const weather = await getWeather(inputText); | ||
|
|
||
| // Validate Api data using yup | ||
| await weatherSchema.validate(weather); | ||
|
|
||
| // update redux | ||
| dispatch(pushLocation(weather)); | ||
|
|
||
| } catch (e) { | ||
| // On validation fail set error message | ||
| setSearchErrors({message: `Could not find the city ${inputText}.`}); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| return ( | ||
| <section className="container"> | ||
| <div className="row justify-content-center"> | ||
| <div className="col col-9"> | ||
| <SearchBarForm | ||
| handleFormSubmit={handleFormSubmit} | ||
| returnDataError={searchErrors} | ||
| /> | ||
| </div> | ||
| </div> | ||
| </section> | ||
| ) | ||
| } |
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.
love this, next time group them in a separate folder like utils or packages