From 415a672af3ff4d46ff7d47b0bd44dde282e4f82f Mon Sep 17 00:00:00 2001 From: Jonas Heinrich Date: Fri, 30 Oct 2020 18:36:01 +0100 Subject: [PATCH] global variable apiUrl --- src/components/Main.vue | 36 +++++++++++++++--------------------- src/main.js | 2 ++ 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/components/Main.vue b/src/components/Main.vue index becc27f..35bffbb 100644 --- a/src/components/Main.vue +++ b/src/components/Main.vue @@ -86,23 +86,7 @@ export default { this.tableData = [] const route = this.$route this.$store.dispatch('setMenuState', route.name) - switch (route.name) { - case 'TOP': - this.loadStations() - break - case 'RECENT': - this.loadStations() - break - case 'NEW': - this.loadStations() - break - case 'FAVORITES': - this.loadStations() - break - case 'CATEGORIES': - this.loadStations() - break - } + this.loadStations(route.name) }, /** * Favor a new station by sending the information to the server @@ -131,7 +115,7 @@ export default { audioPlayer.fade(vm.player.volume, 0, 500) } vm.$store.dispatch('setTitle', station.name) - this.$jquery.get('http://de1.api.radio-browser.info/json/url/' + station.stationuuid, + this.$jquery.get(this.$apiUrl + '/json/url/' + station.stationuuid, { 'User-Agent': 'Nextcloud Radio/1.0.0', // FIXME global version, doesnt seem to work }) @@ -168,16 +152,26 @@ export default { }, /** * Fetching radio stations using Radio-Browser.info API + * @param {String} menuState Entries to load */ - loadStations() { + loadStations(menuState = 'TOP') { + const vm = this if (vm.offset === 0) { vm.pageLoading = true } - this.$jquery.getJSON('https://de1.api.radio-browser.info/json/stations', + + let sortBy = 'clickcount' + if (menuState === 'TOP') { + sortBy = 'clickcount' + } else if (menuState === 'NEW') { + sortBy = 'lastchangetime' + } + + this.$jquery.getJSON(this.$apiUrl + '/json/stations', { limit: 20, - order: 'clickcount', + order: sortBy, reverse: true, offset: vm.offset, 'User-Agent': 'Nextcloud Radio/1.0.0', // FIXME global version, doesnt seem to work diff --git a/src/main.js b/src/main.js index 125428d..779a0b2 100644 --- a/src/main.js +++ b/src/main.js @@ -36,6 +36,8 @@ Vue.prototype.t = translate Vue.prototype.n = translatePlural Vue.prototype.$jquery = jquery +Vue.prototype.$apiUrl = 'https://de1.api.radio-browser.info' + Vue.use(VueBlurHash) export default new Vue({