@@ -8,7 +8,6 @@ import {PropTypes} from 'prop-types'
88import { Event } from '../../utils/ReactAnalytics'
99import { FiPercent } from 'react-icons/fi'
1010import WeatherIconComponent from './WeatherIconComponent'
11- import getWeatherBackground from './../../utils/WeatherBackground'
1211
1312const InfoDetailComponent = ( { weatherCurrent} ) => {
1413 const { weatherUnit, updateWeatherUnit} = useContext ( WeatherUnitContext )
@@ -39,132 +38,95 @@ const InfoDetailComponent = ({weatherCurrent}) => {
3938 : `${ mToK ( weatherCurrent . windSpeed ) } kmph`
4039 }
4140
42- const WET_TYPES = [ 'rain' , 'snow' , 'sleet' , 'hail' ]
43-
44- // return rain or snow svg image for the above wet types
45- const weatherSVG = ( ) => {
46- if ( weatherCurrent . icon === 'snow' ) {
47- return 'snow'
48- }
49- return 'rain'
50- }
51-
5241 return (
5342 < Fragment >
54- < div className = 'relative' >
55- < img
56- src = { `./weather-backgrounds/${ getWeatherBackground (
57- weatherCurrent
58- ) } .jpg`}
59- alt = 'clear day'
60- className = 'w-full h-64 sm:h-48 object-cover object-center'
61- />
62- { /* show rain or snow svg only when weather icon exist in WET_TYPES*/ }
63- < div >
64- { WET_TYPES . includes ( weatherCurrent . icon ) && (
65- < img
66- src = { `./weather-backgrounds/${ weatherSVG ( ) } .svg` }
67- alt = 'clear day'
68- className = 'w-full h-64 sm:h-48 object-cover object-center absolute top-0 right-0 bottom-0 left-0'
69- />
70- ) }
71- </ div >
72- < div
73- className = 'absolute top-0 bottom-0 left-0 right-0 my-auto mx-auto text-light'
74- style = { { background : 'rgba(0,0,0,0.2)' } } >
75- < div className = 'sm:flex-col md:flex md:flex-row justify-between my-2 px-6 sm:mt-5 sm:mb-5 sm:px-4' >
76- < div className = 'flex-col sm:w-full lg:w-1/2' >
77- < div className = 'flex flex-row justify-between sm:justify-start' >
78- < div className = 'flex flex-col justify-center items-center' >
79- < div >
80- { getWeatherIcon ( weatherCurrent ) . startsWith ( 'wi' ) ? (
81- < p
82- className = 'text-6xl sm:mx-2 mt-2'
83- title = { weatherCurrent . summary } >
84- {
85- < WeatherIconComponent
86- type = { getWeatherIcon ( weatherCurrent ) }
87- />
88- }
89- </ p >
90- ) : (
91- < img
92- src = { `./weather/${ getWeatherIcon ( weatherCurrent ) } .svg` }
93- alt = 'icon'
94- title = { weatherCurrent . summary }
95- className = '-mt-2 -ml-4 sm:mx-0 w-32 h-32 object-contain'
96- />
97- ) }
98- </ div >
99- < p className = 'hidden sm:flex font-medium -mt-2 capitalize' >
100- { weatherCurrent . summary }
101- </ p >
102- </ div >
103- < div className = 'flex justify-start items-center sm:-mt-3 sm:ml-3' >
104- < div >
105- < span className = 'text-6xl font-bold' >
106- { computedTempValue ( 'temperature' ) }
107- </ span >
108- </ div >
109- < div className = '-mt-8 mx-2 text-sm' >
110- < sup > o</ sup >
111- < span
112- className = { `cursor-pointer ${
113- weatherUnit === 'F'
114- ? 'font-bold underline'
115- : 'font-light'
116- } `}
117- onClick = { ( ) => unitClick ( 'F' ) } >
118- F
119- </ span >
120- < span className = 'mx-1' > |</ span >
121- < sup > o</ sup >
122- < span
123- className = { `cursor-pointer ${
124- weatherUnit === 'C'
125- ? 'font-bold underline'
126- : 'font-light'
127- } `}
128- onClick = { ( ) => unitClick ( 'C' ) } >
129- C
130- </ span >
131- </ div >
132- </ div >
133- </ div >
134- </ div >
135- { /* weather info */ }
136- < div className = 'flex flex-col justify-center items-center sm:mt-6 sm:w-full lg:w-1/2' >
137- < p className = 'sm:hidden font-medium capitalize text-2xl -mt-2 mb-2' >
138- { weatherCurrent . summary }
139- </ p >
140- < div className = 'text-sm sm:text-lg ml-8' >
141- < div className = 'flex flex-row sm:my-2' >
142- < p className = 'font-light' > Humidity:</ p >
143- < p className = 'mx-1' > { Math . round ( weatherCurrent . humidity ) } </ p >
144- < p className = 'text-sm mt-1' >
145- < FiPercent />
146- </ p >
147- </ div >
148- < div className = 'flex items-center sm:my-2' >
149- < p >
150- < span className = 'font-light' > Wind:</ span >
151- { computedSpeedValue ( ) } { ' ' }
152- </ p >
153- < p className = 'text-3xl' >
43+ < div className = 'sm:flex-col md:flex md:flex-row justify-between my-2 px-6 sm:mt-5 sm:mb-5 sm:px-4' >
44+ < div className = 'flex-col sm:w-full lg:w-1/2' >
45+ < div className = 'flex flex-row justify-between sm:justify-start' >
46+ < div className = 'flex flex-col justify-center items-center' >
47+ < div >
48+ { getWeatherIcon ( weatherCurrent ) . startsWith ( 'wi' ) ? (
49+ < p
50+ className = 'text-6xl sm:mx-2 mt-2'
51+ title = { weatherCurrent . summary } >
15452 {
15553 < WeatherIconComponent
156- type = { getWindDirection ( weatherCurrent . windBearing ) }
54+ type = { getWeatherIcon ( weatherCurrent ) }
15755 />
15856 }
15957 </ p >
160- </ div >
161- < p >
162- < span className = 'font-light sm:my-2' > Feels like:</ span >
163- { computedTempValue ( 'apparentTemperature' ) }
164- < sup > o</ sup >
165- </ p >
58+ ) : (
59+ < img
60+ src = { `./weather/${ getWeatherIcon ( weatherCurrent ) } .svg` }
61+ alt = 'icon'
62+ title = { weatherCurrent . summary }
63+ className = '-mt-2 -ml-4 sm:mx-0 w-32 h-32 object-contain'
64+ />
65+ ) }
16666 </ div >
67+ < p className = 'hidden sm:flex font-medium -mt-2 ml-3 capitalize' >
68+ { weatherCurrent . summary }
69+ </ p >
70+ </ div >
71+ < div className = 'flex justify-start items-center sm:-mt-3 sm:ml-3' >
72+ < div >
73+ < span className = 'text-6xl font-bold' >
74+ { computedTempValue ( 'temperature' ) }
75+ </ span >
76+ </ div >
77+ < div className = '-mt-8 mx-2 text-sm' >
78+ < sup > o</ sup >
79+ < span
80+ className = { `cursor-pointer ${
81+ weatherUnit === 'F' ? 'font-bold underline' : 'font-light'
82+ } `}
83+ onClick = { ( ) => unitClick ( 'F' ) } >
84+ F
85+ </ span >
86+ < span className = 'mx-1' > |</ span >
87+ < sup > o</ sup >
88+ < span
89+ className = { `cursor-pointer ${
90+ weatherUnit === 'C' ? 'font-bold underline' : 'font-light'
91+ } `}
92+ onClick = { ( ) => unitClick ( 'C' ) } >
93+ C
94+ </ span >
95+ </ div >
96+ </ div >
97+ </ div >
98+ </ div >
99+ { /* weather info */ }
100+ < div className = 'flex flex-col justify-center items-center sm:mt-6 sm:w-full lg:w-1/2' >
101+ < p className = 'sm:hidden font-medium capitalize text-2xl -mt-2 mb-2' >
102+ { weatherCurrent . summary }
103+ </ p >
104+ < div className = 'text-sm sm:text-lg ml-8' >
105+ < div className = 'flex flex-row sm:my-2' >
106+ < p className = 'font-light' > Humidity:</ p >
107+ < p className = 'mx-1' > { Math . round ( weatherCurrent . humidity ) } </ p >
108+ < p className = 'text-sm mt-1' >
109+ < FiPercent />
110+ </ p >
111+ </ div >
112+ < div className = 'flex items-center sm:my-2' >
113+ < p >
114+ < span className = 'font-light' > Wind:</ span >
115+ { computedSpeedValue ( ) } { ' ' }
116+ </ p >
117+ < p className = 'text-3xl' >
118+ {
119+ < WeatherIconComponent
120+ type = { getWindDirection ( weatherCurrent . windBearing ) }
121+ />
122+ }
123+ </ p >
167124 </ div >
125+ < p >
126+ < span className = 'font-light sm:my-2' > Feels like:</ span >
127+ { computedTempValue ( 'apparentTemperature' ) }
128+ < sup > o</ sup >
129+ </ p >
168130 </ div >
169131 </ div >
170132 </ div >
0 commit comments