implementing categories

This commit is contained in:
Jonas Heinrich 2020-11-21 23:06:42 +01:00
parent 290d3581dc
commit d5038611e2
3 changed files with 91 additions and 40 deletions

View File

@ -63,6 +63,7 @@ export default {
favorites: [], favorites: [],
showSidebar: false, showSidebar: false,
sidebarStation: {}, sidebarStation: {},
queryParams: {},
}), }),
computed: { computed: {
player() { player() {
@ -223,7 +224,6 @@ export default {
html5: true, html5: true,
volume: vm.player.volume, volume: vm.player.volume,
onplay() { onplay() {
console.log('onplay')
vm.$store.dispatch('isPlaying', true) vm.$store.dispatch('isPlaying', true)
vm.$store.dispatch('isBuffering', false) vm.$store.dispatch('isBuffering', false)
}, },
@ -284,36 +284,63 @@ export default {
let sortBy = 'clickcount' let sortBy = 'clickcount'
if (vm.$route.name === 'CATEGORIES') { if (vm.$route.name === 'CATEGORIES') {
if (vm.$route.path === '/categories') {
vm.tableData = [ vm.tableData = [
{ {
name: t('radio', 'Countries'), name: t('radio', 'Countries'),
type: 'folder', type: 'folder',
path: '#/categories/countries', path: '/categories/countries',
}, },
{ {
name: t('radio', 'States'), name: t('radio', 'States'),
type: 'folder', type: 'folder',
path: '#/categories/states', path: '/categories/states',
}, },
{ {
name: t('radio', 'Languages'), name: t('radio', 'Languages'),
type: 'folder', type: 'folder',
path: '#/categories/languages', path: '/categories/languages',
}, },
{ {
name: t('radio', 'Tags'), name: t('radio', 'Tags'),
type: 'folder', type: 'folder',
path: '#/categories/tags', path: '/categories/tags',
}, },
] ]
vm.pageLoading = false vm.pageLoading = false
return true return true
} else if (vm.$route.params.category === 'tags') {
if (vm.$route.params.query) {
queryURI = this.$apiUrl + '/json/stations/search?tag=' + vm.$route.params.query + '&tagExact=true'
} else {
queryURI = this.$apiUrl + '/json/tags'
}
} else if (vm.$route.params.category === 'countries') {
if (vm.$route.params.query) {
queryURI = this.$apiUrl + '/json/stations/search?country=' + vm.$route.params.query + '&countryExact=true'
} else {
queryURI = this.$apiUrl + '/json/countries'
}
} else if (vm.$route.params.category === 'states') {
if (vm.$route.params.query) {
queryURI = this.$apiUrl + '/json/stations/search?state=' + vm.$route.params.query + '&stateExact=true'
} else {
queryURI = this.$apiUrl + '/json/states'
}
} else if (vm.$route.params.category === 'languages') {
if (vm.$route.params.query) {
queryURI = this.$apiUrl + '/json/stations/search?language=' + vm.$route.params.query + '&languageExact=true'
} else {
queryURI = this.$apiUrl + '/json/languages'
}
}
} }
// Skip loading more stations on certain sites // Skip loading more stations on certain sites
if (vm.tableData.length > 0 if (vm.tableData.length > 0
&& (vm.$route.name === 'FAVORITES' && (vm.$route.name === 'FAVORITES'
|| vm.$route.name === 'RECENT')) { || vm.$route.name === 'RECENT'
|| vm.$route.name === 'CATEGORIES')) {
return true return true
} }
@ -330,23 +357,34 @@ export default {
queryURI = generateUrl('/apps/radio/api/recent') queryURI = generateUrl('/apps/radio/api/recent')
} }
try { if (menuState !== 'CATEGORIES') {
await axios.get(queryURI, { vm.queryParams = {
params: {
limit: 20, limit: 20,
order: sortBy, order: sortBy,
reverse: true, reverse: true,
offset: vm.tableData.length, offset: vm.tableData.length,
}, }
} else {
vm.queryParams = {}
}
try {
await axios.get(queryURI, {
params: vm.queryParams,
}) })
.then(function(response) { .then(function(response) {
for (let i = 0; i < response.data.length; i++) { for (let i = 0; i < response.data.length; i++) {
const obj = response.data[i] const obj = response.data[i]
if (obj.stationuuid) {
let blurHash = vm.blurHashes[obj.stationuuid] let blurHash = vm.blurHashes[obj.stationuuid]
if (!blurHash) { if (!blurHash) {
blurHash = 'L1TSUA?bj[?b~qfQfQj[ayfQfQfQ' blurHash = 'L1TSUA?bj[?b~qfQfQj[ayfQfQfQ'
} }
response.data[i].blurHash = blurHash response.data[i].blurHash = blurHash
} else {
response.data[i].type = 'folder'
response.data[i].path = vm.$route.path + '/' + obj.name
}
} }
vm.tableData = vm.tableData.concat(response.data) vm.tableData = vm.tableData.concat(response.data)
vm.pageLoading = false vm.pageLoading = false

View File

@ -10,7 +10,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<template v-if="stationData[0].type!=='folder'"> <template v-if="!isFolder">
<tr <tr
v-for="(station, idx) in stationData" v-for="(station, idx) in stationData"
:key="idx" :key="idx"
@ -55,11 +55,11 @@
</td> </td>
</tr> </tr>
</template> </template>
<template v-if="stationData[0].type==='folder'"> <template v-if="isFolder">
<tr <tr
v-for="(station, idx) in stationData" v-for="(station, idx) in stationData"
:key="idx" :key="idx"
@click="doPlay(idx, station)"> @click="changeRoute(station.path)">
<td> <td>
<span class="icon-folder" /> <span class="icon-folder" />
</td> </td>
@ -98,6 +98,16 @@ export default {
data: () => ({ data: () => ({
activeItem: null, activeItem: null,
}), }),
computed: {
isFolder() {
if (this.stationData[0]) {
if (this.stationData[0].type === 'folder') {
return true
}
}
return false
},
},
methods: { methods: {
doPlay(idx, station) { doPlay(idx, station) {
this.activeItem = idx this.activeItem = idx
@ -109,6 +119,9 @@ export default {
toggleSidebar(station) { toggleSidebar(station) {
this.$emit('toggleSidebar', station) this.$emit('toggleSidebar', station)
}, },
changeRoute(path) {
this.$router.push({ path })
},
}, },
} }
</script> </script>

View File

@ -33,7 +33,7 @@ const router = new Router({
name: 'FAVORITES', name: 'FAVORITES',
}, },
{ {
path: '/categories', path: '/categories/:category?/:query?',
component: Main, component: Main,
name: 'CATEGORIES', name: 'CATEGORIES',
}, },