starting to implement remove station from favorites

This commit is contained in:
Jonas Heinrich 2020-11-08 09:53:11 +01:00
parent 3efeaa49a4
commit c4d6045194
2 changed files with 32 additions and 9 deletions

View File

@ -97,14 +97,26 @@ export default {
* @param {Object} station Station object
*/
async doFavor(station) {
try {
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'))
if (this.favorites.includes(station.stationuuid)) {
try {
await axios
.delete(generateUrl(`/apps/radio/api/favorites/${station.id}`))
.then(response => {
this.favorites = this.favorites.filter(item => item !== station.stationuuid)
})
} catch (error) {
showError(t('radio', 'Could not remove station from favorites'))
}
} else {
try {
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'))
}
}
},

View File

@ -30,9 +30,20 @@
</td>
<td class="actionColumn">
<Actions>
<ActionButton icon="icon-star" :close-after-click="true" @click="doFavor(idx, station)">
<ActionButton
v-if="!favorites.includes(station.stationuuid)"
icon="icon-star"
:close-after-click="true"
@click="doFavor(idx, station)">
{{ t('radio', 'Add to favorites') }}
</ActionButton>
<ActionButton
v-if="favorites.includes(station.stationuuid)"
icon="icon-star"
:close-after-click="true"
@click="doFavor(idx, station)">
{{ t('radio', 'Remove from favorites') }}
</ActionButton>
<ActionButton icon="icon-info" :close-after-click="true">
{{ t('radio', 'Details') }}
</ActionButton>