-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemperatureDetails.jsx
145 lines (133 loc) · 3.73 KB
/
TemperatureDetails.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import React, { useState } from 'react';
import Forecast from './Forecast';
import WeatherDetail from './WeatherDetail';
import WeatherDateTime from './WeatherDateTime';
const TemperatureDetails = ({ weatherData, setDegreeUnit }) => {
const [isCelsius, setIsCelsius] = useState(true);
const handleDegree = (event) => {
if (event.target.id === 'celsius') {
setIsCelsius(true);
setDegreeUnit('metric');
} else {
setIsCelsius(false);
setDegreeUnit('imperial');
}
};
return (
<div className='w-full max-w-3xl px-6 text-center'>
{/* Date and time */}
<div className='flex flex-wrap items-center justify-center text-base font-light'>
<WeatherDateTime
timestamp={weatherData.dt}
timezone={weatherData.timezone}
/>
</div>
{/* City name */}
<h2 className='my-3 text-3xl font-semibold capitalize'>{`${weatherData.name}, ${weatherData.country}`}</h2>
{/* Weather details */}
<div className='flex flex-col items-center justify-center'>
{/* Weather description */}
<h3 className='text-xl font-medium capitalize text-orange-600'>
{weatherData.description}
</h3>
<div className='my-3 flex flex-wrap items-center justify-between text-center'>
{/* Weather Icon Image */}
<img
src={`https://openweathermap.org/img/wn/${weatherData.icon}@2x.png`}
alt='Weather Icon'
className='w-24'
/>
{/* Weather Temperature */}
<div className='flex items-center justify-between p-3 text-lg capitalize'>
<span className='text-5xl'>
{Math.round(weatherData.temp)}°
</span>
<div className='p-2 font-light'>
<span
id='celsius'
className={`cursor-pointer ${
isCelsius ? 'text-2xl font-normal' : 'text-gray-300'
} `}
onClick={handleDegree}
>
°C
</span>
<span className='mx-2'>|</span>
<span
id='fahrenheit'
className={`cursor-pointer ${
isCelsius ? 'text-gray-300' : 'text-2xl font-normal'
} `}
onClick={handleDegree}
>
°F
</span>
</div>
</div>
{/* Weather extra info: Part 1 */}
<div className='flex flex-col items-start'>
<WeatherDetail
iconName='UilTemperature'
title='real feel'
value={Math.round(weatherData.feels_like)}
type='degree'
/>
<WeatherDetail
iconName='UilTear'
title='humidity'
value={Math.round(weatherData.humidity)}
type='percentage'
/>
<WeatherDetail
iconName='UilWind'
title='wind'
value={Math.round(weatherData.speed)}
type='speed'
isCelsius={isCelsius}
/>
</div>
</div>
{/* Weather extra info: Part 2 */}
<div className='flex flex-wrap items-center justify-between'>
<WeatherDetail
iconName='UilSun'
title='rise'
value={{ dt: weatherData.sunrise, timezone: weatherData.timezone }}
type='time'
/>
<WeatherDetail
iconName='UilSunset'
title='set'
value={{ dt: weatherData.sunset, timezone: weatherData.timezone }}
type='time'
/>
<WeatherDetail
iconName='UilArrowUp'
title='high'
value={Math.round(weatherData.temp_max)}
type='degree'
/>
<WeatherDetail
iconName='UilArrowDown'
title='low'
value={Math.round(weatherData.temp_min)}
type='degree'
/>
</div>
</div>
{/* Hourly forecast details */}
<Forecast
title='hourly'
forecastData={weatherData.hourly}
timezone={weatherData.timezone}
/>
{/* Daily forecast details */}
<Forecast
title='daily'
forecastData={weatherData.daily}
timezone={weatherData.timezone}
/>
</div>
);
};
export default TemperatureDetails;