From 758ae54b41306fc3a92e66ad06ba5710b55bc049 Mon Sep 17 00:00:00 2001 From: elminhoemmanuel Date: Wed, 20 Oct 2021 05:10:09 -0700 Subject: [PATCH] finished working on all user stories --- components/LeftView.js | 78 +++++++++++++++++++++++++----- components/PrimaryBtn.js | 2 +- components/RightView.js | 78 +++++++++++++++++++----------- components/SideBar.js | 43 ++++++++++++---- components/SmallWeatherCard.js | 59 ++++++++++++++++++++-- package-lock.json | 55 +++++++++++++++++++++ package.json | 2 + pages/index.js | 63 ++++++++++++++++++------ redux/actions/fetch.js | 24 +++++++++ redux/actions/search.js | 47 ++++++++++++++++++ redux/actions/types.js | 23 ++++++++- redux/reducers/CombinedReducers.js | 4 +- redux/reducers/fetch.js | 60 +++++++++++++++++++++++ redux/reducers/search.js | 48 ++++++++++++++++-- styles/globals.scss | 39 ++++++++------- 15 files changed, 532 insertions(+), 93 deletions(-) create mode 100644 redux/actions/fetch.js create mode 100644 redux/reducers/fetch.js diff --git a/components/LeftView.js b/components/LeftView.js index b69f443..c75ecfa 100644 --- a/components/LeftView.js +++ b/components/LeftView.js @@ -1,13 +1,58 @@ -import React from 'react' +import React, { useState, useEffect } from 'react' import PrimaryBtn from './PrimaryBtn' import { IoMdLocate } from "react-icons/io" +import { MdLocationPin } from "react-icons/md" import RoundBtn from './RoundBtn' import { useDispatch, useSelector } from 'react-redux' import { TOGGLE_SEARCH } from "../redux/actions/types" +import moment from "moment" const LeftView = () => { const dispatch = useDispatch() + const { details, error, loading, unit } = useSelector((state) => state.fetch); + const weathers = details.consolidated_weather + const celToFah = celsius => celsius * 9 / 5 + 32; + const getCorrectImg = (symbol) => { + switch (symbol) { + case "s": + return "/images/Shower.png" + + case "c": + return "/images/Clear.png" + + case "lc": + return "/images/LightCloud.png" + + case "hc": + return "/images/HeavyCloud.png" + + case "lr": + return "/images/LightRain.png" + + case "hr": + return "/images/HeavyRain.png" + + case "t": + return "/images/Thunderstorm.png" + + case "h": + return "/images/Hail.png" + + case "sl": + return "/images/Sleet.png" + + case "sn": + return "/images/Snow.png" + + default: + break; + } + } + + // useEffect(() => { + // setWeathers(details.consolidated_weather); + // }, [weathers]) return (
@@ -18,8 +63,8 @@ const LeftView = () => {
{ dispatch({type:TOGGLE_SEARCH}) }} + addStyle="block bg-bgbtn text-maytext hover:bg-gray-600 px-4 py-2" + clicked={() => { dispatch({ type: TOGGLE_SEARCH }) }} /> {
- main weather image + main weather image
-

- 15 - °C -

+ { + unit === "cel" && +

+ {Math.round(weathers[0].the_temp)} + °C +

+ } + + { + unit === "fah" && +

+ {Math.round(celToFah(weathers[0].the_temp))} + °F +

+ }

- Shower + {weathers[0].weather_state_name}

-

Today - Fri, 5 Jun

-

Helsinki

+

Today - {moment(weathers[0].applicable_date).format("ddd, D MMM")}

+

{details.title}

diff --git a/components/PrimaryBtn.js b/components/PrimaryBtn.js index 2481004..473168c 100644 --- a/components/PrimaryBtn.js +++ b/components/PrimaryBtn.js @@ -2,7 +2,7 @@ import React from 'react' const PrimaryBtn = ({ btnText , clicked, addStyle}) => { return ( - ) diff --git a/components/RightView.js b/components/RightView.js index 4d62120..dd9167c 100644 --- a/components/RightView.js +++ b/components/RightView.js @@ -1,33 +1,55 @@ -import React from 'react' +import React, { useEffect } from "react" import RoundBtn from './RoundBtn' -import { fivedays } from './Data' import SmallWeatherCard from './SmallWeatherCard' import ProgressBar from './ProgressBar' import { BsFillPlayFill } from "react-icons/bs" import Link from "next/link" -import NextNprogress from 'nextjs-progressbar'; +import { useDispatch, useSelector } from 'react-redux' +import { SET_UNIT } from "../redux/actions/types" + const RightView = () => { + + const dispatch = useDispatch() + const { details, unit } = useSelector((state) => state.fetch); + const weathers = details.consolidated_weather + return (
- °C} - addStyle="h-10 w-10 mr-2 text-black hover:text-white bg-gray-300 hover:bg-gray-600" - clicked={() => { }} - /> - - °F} - addStyle="h-10 w-10 bg-bgbtn hover:bg-gray-600 text-maytext" - clicked={() => { }} - /> + { + unit === "cel" ? + °C} + addStyle="mr-2 h-10 w-10 bg-gray-400 hover:bg-gray-400 hover:text-white text-white" + clicked={() => { dispatch({ type: SET_UNIT, payload: "cel" }) }} + /> : + °C} + addStyle="mr-2 h-10 w-10 bg-gray-600 hover:bg-gray-400 hover:text-white text-maytext" + clicked={() => { dispatch({ type: SET_UNIT, payload: "cel" }) }} + /> + } + + { + unit === "fah" ? + °F} + addStyle="h-10 w-10 bg-gray-400 hover:bg-gray-400 hover:text-white text-white" + clicked={() => { dispatch({ type: SET_UNIT, payload: "fah" }) }} + /> : + °F} + addStyle="h-10 w-10 bg-gray-600 hover:bg-gray-400 hover:text-white text-maytext" + clicked={() => { dispatch({ type: SET_UNIT, payload: "fah" }) }} + /> + }
{ - fivedays.map(item => ( - + weathers.filter((item, i) => i > 0).map((item, j) => ( + )) }
@@ -42,8 +64,8 @@ const RightView = () => {

Wind status

- 7 - mph + {Math.round(weathers[0].wind_speed)} + mph

@@ -52,7 +74,7 @@ const RightView = () => { addStyle="mr-2 pointer:events-none h-7 w-7 bg-bgbtn hover:bg-gray-600 text-maytext" clicked={() => { }} /> -

WSW

+

{weathers[0].wind_direction_compass}

@@ -61,8 +83,8 @@ const RightView = () => {

Humidity

- 84 - % + {weathers[0].humidity} + %

@@ -71,8 +93,8 @@ const RightView = () => { 50 100
- - + +
%
@@ -84,8 +106,8 @@ const RightView = () => {

Visibility

- 6,4 - miles + {Math.round(weathers[0].visibility)} + miles

@@ -94,13 +116,13 @@ const RightView = () => {

Air Pressure

- 998 - mb + {Math.round(weathers[0].visibility)} + mb

-

Coded by elminhoemmanuel

+

Coded by elminhoemmanuel

diff --git a/components/SideBar.js b/components/SideBar.js index 8b70036..36ccdc0 100644 --- a/components/SideBar.js +++ b/components/SideBar.js @@ -1,19 +1,31 @@ -import React, {useState} from 'react' +import React, { useState, useEffect} from 'react' import RoundBtn from './RoundBtn' import { AiOutlineClose, AiOutlineSearch, AiOutlineRight } from "react-icons/ai" import { useDispatch, useSelector } from 'react-redux' -import { TOGGLE_SEARCH } from "../redux/actions/types" +import { TOGGLE_SEARCH, RESET_ERROR_SEARCH, RESET_NOT_FOUND } from "../redux/actions/types" +import { search } from "../redux/actions/search" import PrimaryBtn from './PrimaryBtn' const SideBar = () => { + const [searchValue, setSearchValue] = useState("") const dispatch = useDispatch() + const { loadingSearch, errorSearch, notFound } = useSelector((state) => state.search); const [showIcon, setShowIcon] = useState({ first:false, second:false, third:false, }) + const handleSearch = (fieldValue) => { + dispatch(search(fieldValue)); + } + + useEffect(() => { + dispatch({type:RESET_ERROR_SEARCH}); + dispatch({type:RESET_NOT_FOUND}); + }, []) + return (
@@ -25,9 +37,11 @@ const SideBar = () => { />
-
+
{setSearchValue(e.target.value)}} type="text" placeholder="search location" className="w-full pl-8 py-2 pr-2 bg-transparent text-inputtext placeholder-inputtext border border-gray-500 focus:outline-none text-sm" @@ -37,15 +51,24 @@ const SideBar = () => {
{ }} + btnText={ + loadingSearch ? +
+ : + "Search" + } + addStyle="p-2 flex items-center justify-center w-full bg-btnblue text-white border border-btnblue hover:border-blue-800 hover:bg-blue-800" + clicked={() => { handleSearch(searchValue) }} />
+ { errorSearch !=="" &&

Something went wrong, try again

} + { notFound &&

No data found for that location

} +
- - -