fix adding and removing favorites

This commit is contained in:
Jonas Heinrich 2020-11-09 10:46:10 +01:00
parent f3a65ae93a
commit 1337754515
3 changed files with 12 additions and 3 deletions

View File

@ -98,7 +98,7 @@ return [
// Api
[
'name' => 'station_api#preflighted_cors',
'name' => 'favorite_api#preflighted_cors',
'url' => '/api/0.1/{path}',
'verb' => 'OPTIONS',
'requirements' => ['path' => '.+']

View File

@ -15,6 +15,8 @@ class FavoriteController extends Controller {
/** @var string */
private $userId;
use Errors;
public function __construct(IRequest $request,
StationService $service,
$userId) {

View File

@ -108,7 +108,7 @@ export default {
await axios
.delete(generateUrl(`/apps/radio/api/favorites/${stationid}`))
.then(response => {
this.favorites = this.favorites.filter(item => item !== station.stationuuid)
this.favorites = this.favorites.filter(item => item[1] !== station.stationuuid)
})
} catch (error) {
showError(t('radio', 'Could not remove station from favorites'))
@ -118,7 +118,7 @@ export default {
await axios
.post(generateUrl('/apps/radio/api/favorites'), station)
.then(response => {
this.favorites.push(station.stationuuid)
this.favorites.push([response.data.id, station.stationuuid])
})
} catch (error) {
showError(t('radio', 'Could not favor station'))
@ -230,9 +230,16 @@ export default {
}
}
},
loadSettings() {
axios.defaults.headers.common = {
'User-Agent': 'Nextcloud Radio App/1.0', // FIXME: Reference global version number
}
this.$store.dispatch('getVolumeState')
},
async loadFavorites() {
const vm = this
await axios.get(generateUrl('/apps/radio/api/favorites'))