fix showing star on favoring station

This commit is contained in:
Jonas Heinrich 2020-11-08 09:35:08 +01:00
parent 9428cf582e
commit 3efeaa49a4
2 changed files with 18 additions and 5 deletions

View File

@ -11,6 +11,7 @@
<Table
v-if="!pageLoading"
:station-data="tableData"
:favorites="favorites"
@doPlay="doPlay"
@doFavor="doFavor" />
<EmptyContent
@ -97,8 +98,12 @@ export default {
*/
async doFavor(station) {
try {
await axios.post(generateUrl('/apps/radio/api/favorites'), station)
} catch (e) {
await axios
.post(generateUrl('/apps/radio/api/favorites'), station)
.then(response => {
this.favorites.push(station.stationuuid)
})
} catch (error) {
showError(t('radio', 'Could not favor station'))
}
},
@ -211,9 +216,14 @@ export default {
this.$store.dispatch('getVolumeState')
},
async loadFavorites() {
const vm = this
await axios.get(generateUrl('/apps/radio/api/favorites'))
.then(function(response) {
this.favorites = response.data
const favorites = []
for (let i = 0, len = response.data.length; i < len; i++) {
favorites.push(response.data[i].stationuuid)
}
vm.favorites = favorites
})
},
},

View File

@ -21,7 +21,7 @@
height="32"
:hash="station.blurHash"
:src="station.favicon" />
<span :class="{ 'icon-starred': stationsFavored.includes(idx) }" />
<span :class="{ 'icon-starred': favorites.includes(station.stationuuid) }" />
</td>
<td class="nameColumn" @click="doPlay(idx, station)">
<span class="innernametext">
@ -54,6 +54,10 @@ export default {
ActionButton,
},
props: {
favorites: {
type: Array,
default() { return [] },
},
stationData: {
type: Array,
default() { return [] },
@ -61,7 +65,6 @@ export default {
},
data: () => ({
activeItem: null,
stationsFavored: [1, 2, 3, 4],
}),
methods: {
doPlay(idx, station) {