diff --git a/src/components/Main.vue b/src/components/Main.vue index 1ee7abf..3000fa7 100644 --- a/src/components/Main.vue +++ b/src/components/Main.vue @@ -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')) + } } }, diff --git a/src/components/Table.vue b/src/components/Table.vue index ab2438a..95c6da0 100644 --- a/src/components/Table.vue +++ b/src/components/Table.vue @@ -30,9 +30,20 @@