further tests with routing

This commit is contained in:
Jonas Heinrich 2020-10-20 15:52:12 +02:00
parent 9ad8935139
commit 08d1f95eac
2 changed files with 34 additions and 17 deletions

View File

@ -45,27 +45,52 @@ export default {
tableData: [], tableData: [],
offset: 0, offset: 0,
}), }),
watch: {
$route: 'onRoute',
},
mounted() { mounted() {
this.loadStations() this.loadStations()
this.scroll() this.scroll()
}, },
methods: { methods: {
async onRoute() {
const route = this.$route
switch (route.name) {
case this.routes.TOP:
console.log('new route: TOP')
break
case this.routes.RECENT:
console.log('new route: RECENT')
break
case this.routes.FAVORITES:
console.log('new route: FAVORITES')
break
case this.routes.CATEGORIES:
console.log('new route: CATEGORIES')
break
}
},
/** /**
* Create a new note by sending the information to the server * Favor a new station by sending the information to the server
* @param {Object} note Note object * @param {Object} station Station object
*/ */
async doFavor(station) { async doFavor(station) {
try { try {
const response = await axios.post(generateUrl('/apps/radio/notes'), note) const response = await axios.post(generateUrl('/apps/radio/radio'), station)
const index = this.notes.findIndex((match) => match.id === this.currentNoteId) console.log(response)
this.$set(this.notes, index, response.data) // const index = this.stations.findIndex((match) => match.id === this.currentStationId)
this.currentNoteId = response.data.id // this.$set(this.stations, index, response.data)
// this.currentStationId = response.data.id
} catch (e) { } catch (e) {
console.error(e) console.error(e)
showError(t('radio', 'Could not favor station')) showError(t('radio', 'Could not favor station'))
} }
this.updating = false this.updating = false
}, },
/**
* Start playing a radio station and counting the playback
* @param {Object} station Station object
*/
doPlay(station) { doPlay(station) {
if (audioPlayer !== null) { if (audioPlayer !== null) {
audioPlayer.fade(100, 0, 500) // FIXME persistent volume state audioPlayer.fade(100, 0, 500) // FIXME persistent volume state
@ -85,6 +110,9 @@ export default {
const stationMetadata = document.getElementById('stationMetadata') const stationMetadata = document.getElementById('stationMetadata')
stationMetadata.textContent = station.name stationMetadata.textContent = station.name
}, },
/**
* Fetching radio stations using Radio-Browser.info API
*/
loadStations() { loadStations() {
const vm = this const vm = this
this.$jquery.getJSON('https://de1.api.radio-browser.info/json/stations/search', this.$jquery.getJSON('https://de1.api.radio-browser.info/json/stations/search',
@ -99,12 +127,6 @@ export default {
vm.tableData = vm.tableData.concat(data) vm.tableData = vm.tableData.concat(data)
vm.offset += 20 vm.offset += 20
}) })
},
watch: {
$route(to, from) {
console.log(to)
console.log(from)
},
}, },
scroll() { scroll() {
window.onscroll = () => { window.onscroll = () => {

View File

@ -35,10 +35,5 @@ Vue.prototype.$jquery = jquery
export default new Vue({ export default new Vue({
el: '#content', el: '#content',
router, router,
methods: {
doPlay() {
console.log('event handled!')
},
},
render: h => h(App), render: h => h(App),
}) })