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,6 +97,17 @@ export default {
* @param {Object} station Station object * @param {Object} station Station object
*/ */
async doFavor(station) { async doFavor(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 { try {
await axios await axios
.post(generateUrl('/apps/radio/api/favorites'), station) .post(generateUrl('/apps/radio/api/favorites'), station)
@ -106,6 +117,7 @@ export default {
} catch (error) { } catch (error) {
showError(t('radio', 'Could not favor station')) showError(t('radio', 'Could not favor station'))
} }
}
}, },
/** /**

View File

@ -30,9 +30,20 @@
</td> </td>
<td class="actionColumn"> <td class="actionColumn">
<Actions> <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') }} {{ t('radio', 'Add to favorites') }}
</ActionButton> </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"> <ActionButton icon="icon-info" :close-after-click="true">
{{ t('radio', 'Details') }} {{ t('radio', 'Details') }}
</ActionButton> </ActionButton>