-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcurrent-weather.component.ts
More file actions
140 lines (126 loc) · 5 KB
/
Copy pathcurrent-weather.component.ts
File metadata and controls
140 lines (126 loc) · 5 KB
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
import { Component, computed, input } from '@angular/core';
import { WeatherData } from '../types/weather.types';
import { WeatherUtils } from '../utils/weather.utils';
@Component({
selector: 'app-current-weather',
template: `
@if (weatherData(); as weatherData) {
<section class="current-section">
<h2 class="section-title">Current Weather</h2>
<div class="weather-card" data-testid="current-weather">
<div class="current-weather">
<h3 class="current-weather__location" data-testid="current-location">
{{ locationLabel() }}
</h3>
<div class="current-weather__main">
<div class="current-weather__icon" data-testid="current-icon">
{{ weatherIcon() }}
</div>
<div class="current-weather__temp-group">
<div class="current-weather__temp" data-testid="current-temperature">
{{ currentTemperature() }}
</div>
<div
class="current-weather__condition {{ conditionClass() }}"
data-testid="current-condition"
>
{{ weatherDescription() }}
</div>
</div>
</div>
<div class="current-weather__details">
<div class="weather-detail">
<div class="weather-detail__label">Feels like</div>
<div class="weather-detail__value" data-testid="feels-like">
{{ apparentTemperature() }}
</div>
</div>
<div class="weather-detail">
<div class="weather-detail__label">Humidity</div>
<div class="weather-detail__value" data-testid="humidity">
{{ humidity() }}
</div>
</div>
<div class="weather-detail">
<div class="weather-detail__label">Wind Speed</div>
<div class="weather-detail__value" data-testid="wind-speed">
{{ windSpeed() }}
</div>
</div>
<div class="weather-detail">
<div class="weather-detail__label">Pressure</div>
<div class="weather-detail__value" data-testid="pressure">
{{ pressure() }}
</div>
</div>
<div class="weather-detail">
<div class="weather-detail__label">Cloud Cover</div>
<div class="weather-detail__value" data-testid="cloud-cover">
{{ cloudCover() }}
</div>
</div>
<div class="weather-detail">
<div class="weather-detail__label">Wind Direction</div>
<div class="weather-detail__value" data-testid="wind-direction">
{{ windDirection() }}
</div>
</div>
</div>
</div>
</div>
</section>
}
`
})
export class CurrentWeatherComponent {
readonly weatherData = input<WeatherData | null>(null);
readonly locationLabel = computed(() => {
const weatherData = this.weatherData();
if (!weatherData) {
return '';
}
return weatherData.country
? `${weatherData.locationName}, ${weatherData.country}`
: (weatherData.locationName ?? '');
});
readonly weatherIcon = computed(() => {
const current = this.weatherData()?.current;
return current ? WeatherUtils.getWeatherIcon(current.weather_code, current.is_day) : '';
});
readonly currentTemperature = computed(() => {
const current = this.weatherData()?.current;
return current ? WeatherUtils.formatTemperature(current.temperature_2m) : '';
});
readonly conditionClass = computed(() => {
const current = this.weatherData()?.current;
return current ? WeatherUtils.getConditionClass(current.weather_code) : '';
});
readonly weatherDescription = computed(() => {
const current = this.weatherData()?.current;
return current ? WeatherUtils.getWeatherDescription(current.weather_code) : '';
});
readonly apparentTemperature = computed(() => {
const current = this.weatherData()?.current;
return current ? WeatherUtils.formatTemperature(current.apparent_temperature) : '';
});
readonly humidity = computed(() => {
const current = this.weatherData()?.current;
return current ? WeatherUtils.formatPercentage(current.relative_humidity_2m) : '';
});
readonly windSpeed = computed(() => {
const current = this.weatherData()?.current;
return current ? WeatherUtils.formatWindSpeed(current.wind_speed_10m) : '';
});
readonly pressure = computed(() => {
const current = this.weatherData()?.current;
return current ? WeatherUtils.formatPressure(current.pressure_msl) : '';
});
readonly cloudCover = computed(() => {
const current = this.weatherData()?.current;
return current ? WeatherUtils.formatPercentage(current.cloud_cover) : '';
});
readonly windDirection = computed(() => {
const current = this.weatherData()?.current;
return current ? WeatherUtils.getWindDirection(current.wind_direction_10m) : '';
});
}