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