X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fcomponents%2Fservices%2FOpenWeather.vue;h=ba0be96e92e56e421b173b518e7f313ca3551f9e;hb=5418c6291a39d27aeee471673adba742080e1ccb;hp=7352b9be0ea4d540e8cb288948621eca4ee4da7b;hpb=f2c901a1ec45c91a3fb02333a61bb9d0c82e2859;p=github%2Fbastienwirtz%2Fhomer.git diff --git a/src/components/services/OpenWeather.vue b/src/components/services/OpenWeather.vue index 7352b9b..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}`; - }, - }, };