From 593f8afc909e166260f32a9e97f8d54d941802e6 Mon Sep 17 00:00:00 2001 From: Dick Wolff Date: Tue, 12 Jan 2021 11:35:57 +0100 Subject: Added OpenWeather service component. --- src/components/services/OpenWeather.vue | 99 +++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/components/services/OpenWeather.vue (limited to 'src/components/services/OpenWeather.vue') diff --git a/src/components/services/OpenWeather.vue b/src/components/services/OpenWeather.vue new file mode 100644 index 0000000..30abb2d --- /dev/null +++ b/src/components/services/OpenWeather.vue @@ -0,0 +1,99 @@ + + + + + \ No newline at end of file -- cgit v1.2.3 From b79561bc9c59d79875a9931d235774333579a363 Mon Sep 17 00:00:00 2001 From: Dick Wolff Date: Tue, 12 Jan 2021 11:39:27 +0100 Subject: Format file. --- src/components/services/OpenWeather.vue | 62 ++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 28 deletions(-) (limited to 'src/components/services/OpenWeather.vue') diff --git a/src/components/services/OpenWeather.vue b/src/components/services/OpenWeather.vue index 30abb2d..a9310ee 100644 --- a/src/components/services/OpenWeather.vue +++ b/src/components/services/OpenWeather.vue @@ -6,7 +6,11 @@
- +
@@ -21,10 +25,10 @@ {{ item.subtitle }}

@@ -47,36 +51,38 @@ export default { data: () => ({ api: { name: "", - weather: [{ - main: "", - description: "", - icon: "" - }], + weather: [ + { + main: "", + description: "", + icon: "", + }, + ], main: { - temp: "", - humidity: "" - } - } + temp: "", + humidity: "", + }, + }, }), computed: { temp: function () { if (this.api) { - return parseInt(this.api.main.temp).toFixed(1); + return parseInt(this.api.main.temp).toFixed(1); + } + return ""; + }, + image: function () { + if (this.api) { + return this.api.weather[0].icon; + } + return ""; + }, + conditions: function () { + if (this.api) { + return this.api.weather[0].description; } return ""; }, - image: function () { - if (this.api) { - return this.api.weather[0].icon; - } - return ""; - }, - conditions: function () { - if (this.api) { - return this.api.weather[0].description; - } - return ""; - } }, created() { this.fetchStatus(); @@ -96,4 +102,4 @@ export default { .media-left img { max-height: 100%; } - \ No newline at end of file + -- cgit v1.2.3 From fd12de9ebd7a75ca2f31e8b28bd2c5ac10c46e21 Mon Sep 17 00:00:00 2001 From: Dick Wolff Date: Wed, 13 Jan 2021 21:22:35 +0100 Subject: Improvements --- src/components/services/OpenWeather.vue | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/components/services/OpenWeather.vue') diff --git a/src/components/services/OpenWeather.vue b/src/components/services/OpenWeather.vue index a9310ee..b1e5c57 100644 --- a/src/components/services/OpenWeather.vue +++ b/src/components/services/OpenWeather.vue @@ -4,7 +4,7 @@
-
+
-- cgit v1.2.3 From 9e0ef05efe00ffd98ff6c7314a67e8a05505dcc4 Mon Sep 17 00:00:00 2001 From: Dick Wolff Date: Wed, 13 Jan 2021 21:27:19 +0100 Subject: Removed URL and made fixed. --- src/components/services/OpenWeather.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/components/services/OpenWeather.vue') diff --git a/src/components/services/OpenWeather.vue b/src/components/services/OpenWeather.vue index b1e5c57..c535a89 100644 --- a/src/components/services/OpenWeather.vue +++ b/src/components/services/OpenWeather.vue @@ -89,7 +89,7 @@ export default { }, methods: { fetchStatus: async function () { - const url = `${this.item.url}?q=${this.item.location}&appid=${this.item.apiKey}&units=${this.item.units}`; + const url = `https://api.openweathermap.org/data/2.5/weather?q=${this.item.location}&appid=${this.item.apiKey}&units=${this.item.units}`; this.api = await fetch(url) .then((response) => response.json()) .catch((e) => console.log(e)); -- cgit v1.2.3 From fb158d4767b85160c0c2c5fea5c6429c265576a9 Mon Sep 17 00:00:00 2001 From: Dick Wolff Date: Wed, 13 Jan 2021 22:19:17 +0100 Subject: Error handling and fixed link to city. --- src/components/services/OpenWeather.vue | 40 +++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'src/components/services/OpenWeather.vue') diff --git a/src/components/services/OpenWeather.vue b/src/components/services/OpenWeather.vue index c535a89..8029716 100644 --- a/src/components/services/OpenWeather.vue +++ b/src/components/services/OpenWeather.vue @@ -1,7 +1,7 @@

@@ -49,7 +54,9 @@ export default { item: Object, }, data: () => ({ + error: false, api: { + id: "", name: "", weather: [ { @@ -65,8 +72,14 @@ export default { }, }), computed: { - temp: function () { + locationId: function () { if (this.api) { + return this.api.id; + } + return ""; + }, + temp: function () { + if (this.api && this.api.main.temp !== "") { return parseInt(this.api.main.temp).toFixed(1); } return ""; @@ -92,13 +105,19 @@ export default { const url = `https://api.openweathermap.org/data/2.5/weather?q=${this.item.location}&appid=${this.item.apiKey}&units=${this.item.units}`; this.api = await fetch(url) .then((response) => response.json()) - .catch((e) => console.log(e)); + .catch((e) => { + this.error = true; + console.log(e) + }); }, }, };