X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcomponents%2Fservices%2FOpenWeather.vue;h=ba0be96e92e56e421b173b518e7f313ca3551f9e;hb=23990e85090b425e98e563e2e390044d0695c19d;hp=09ff76a3d07e04ec9c015fba6d727b5b3042af9a;hpb=6173d7df609bc3ab071d5d9e34ce1eb1cb05d99e;p=github%2Fbastienwirtz%2Fhomer.git
diff --git a/src/components/services/OpenWeather.vue b/src/components/services/OpenWeather.vue
index 09ff76a..ba0be96 100644
--- a/src/components/services/OpenWeather.vue
+++ b/src/components/services/OpenWeather.vue
@@ -22,7 +22,7 @@
{{ name }}
- {{ temp | tempSuffix(this.item.units) }}
+ {{ temperature }}
@@ -50,6 +50,19 @@ export default {
conditions: null,
error: false,
}),
+ computed: {
+ temperature: function () {
+ if (!this.temp) return "";
+
+ let unit = "K";
+ if (this.item.units === "metric") {
+ unit = "°C";
+ } else if (this.item.units === "imperial") {
+ unit = "°F";
+ }
+ return `${this.temp} ${unit}`;
+ },
+ },
created() {
this.fetchWeather();
},
@@ -64,7 +77,8 @@ export default {
locationQuery = `q=${this.item.location}`;
}
- const url = `https://api.openweathermap.org/data/2.5/weather?${locationQuery}&appid=${this.item.apiKey}&units=${this.item.units}`;
+ const apiKey = this.item.apikey || this.item.apiKey;
+ const url = `https://api.openweathermap.org/data/2.5/weather?${locationQuery}&appid=${apiKey}&units=${this.item.units}`;
fetch(url)
.then((response) => {
if (!response.ok) {
@@ -85,19 +99,6 @@ export default {
});
},
},
- filters: {
- tempSuffix: function (value, type) {
- if (!value) return "";
-
- let unit = "K";
- if (type === "metric") {
- unit = "°C";
- } else if (type === "imperial") {
- unit = "°F";
- }
- return `${value} ${unit}`;
- },
- },
};