From f75329e9fc5940446cd6d0f259e59d8b757d4057 Mon Sep 17 00:00:00 2001 From: Thomas Ballmann Date: Mon, 30 Nov 2020 21:34:24 +0100 Subject: [PATCH] #42 finalize weather settings --- app/src/components/WeatherFindLocation.vue | 55 +++++--- app/src/views/Weather.vue | 145 ++++++++++----------- lib/app/app.cpp | 2 + 3 files changed, 112 insertions(+), 90 deletions(-) diff --git a/app/src/components/WeatherFindLocation.vue b/app/src/components/WeatherFindLocation.vue index ab40c82..b360b10 100644 --- a/app/src/components/WeatherFindLocation.vue +++ b/app/src/components/WeatherFindLocation.vue @@ -4,7 +4,7 @@ :disabled="!api" :items="entries" :loading="isLoading" - :search-input.sync="search" + :search-input.sync="searchInput" no-filter _hide-no-data item-text="name" @@ -12,6 +12,8 @@ label="Location" placeholder="Start typing to Search" prepend-icon="$place" + return-object + clearable > @@ -60,6 +62,10 @@ type: String, required: true, }, + search: { + type: String, + required: false, + }, lang: { type: String, required: true, @@ -74,13 +80,16 @@ entries: [], isLoading: false, model: null, - search: null, + searchInput: null, }), watch: { - model (val) { - this.$emit('update:location', val) + model (item) { + if (item) { + this.$emit('update:location', item.id) + this.$emit('update:search', item.label) + } }, - search (val) { + searchInput (val) { if (!val || val.length < 3) { return } @@ -103,19 +112,31 @@ axios.get(url) .then(res => { - this.entries = res.data.list + const entries = [] + + res.data.list.forEach((item) => { + entries.push({ + id: item.id, + label: item.name + ', ' + item.sys.country, + temp: item.main.temp, + country: item.sys.country, + weather: { + icon: item.weather[0].icon, + description: item.weather[0].description, + }, + }) + }) + + this.entries = entries this.isLoading = false }) }, }, created () { - // TODO + // create entry for the current item this.entries = [{ - name: 'Freilassing', - sys: { - country: 'DE', - }, id: this.location, + label: this.search, }] this.model = this.location }, diff --git a/app/src/views/Weather.vue b/app/src/views/Weather.vue index 2aa3a54..ba54b9a 100644 --- a/app/src/views/Weather.vue +++ b/app/src/views/Weather.vue @@ -1,75 +1,73 @@