Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

πŸ› Fixes duplicate forecase entries in weather (#1887)

Alicia Sykes271eb268eb48
diff --git a/src/components/Widgets/WeatherForecast.vue b/src/components/Widgets/WeatherForecast.vue
index c95c045d..82a9e707 100644
--- a/src/components/Widgets/WeatherForecast.vue
+++ b/src/components/Widgets/WeatherForecast.vue
@@ -57,7 +57,8 @@ export default {
},
endpoint() {
const { apiKey, city } = this.options;
- const params = `?q=${city}&cnt=${this.numDays}&units=${this.units}&appid=${apiKey}`;
+ const cnt = this.numDays * 8; // API returns 3-hourly entries; request enough to cover numDays
+ const params = `?q=${city}&cnt=${cnt}&units=${this.units}&appid=${apiKey}`;
return `${widgetApiEndpoints.weatherForecast}${params}`;
},
tempDisplayUnits() {
@@ -89,13 +90,17 @@ export default {
fetchData() {
this.makeRequest(this.endpoint).then(this.processData);
},
- /* Process the results from the Axios request */
+ /* Process the results from the Axios request, deduplicating by date */
processData(dataList) {
+ const seenDates = {};
const uiWeatherData = [];
- dataList.list.forEach((day, index) => {
+ dataList.list.forEach((day) => {
+ const date = this.dateFromStamp(day.dt);
+ if (seenDates[date] || uiWeatherData.length >= this.numDays) return;
+ seenDates[date] = true;
uiWeatherData.push({
- index,
- date: this.dateFromStamp(day.dt),
+ index: uiWeatherData.length,
+ date,
icon: day.weather[0].icon,
main: day.weather[0].main,
description: day.weather[0].description,