link to album views from home page
This commit is contained in:
parent
9c93ec6e56
commit
2bcafbffaa
@ -22,7 +22,7 @@
|
|||||||
</small>
|
</small>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<router-link class="nav-link" :to="{name: 'albums'}">
|
<router-link class="nav-link" :to="{name: 'albums', params: {sort: 'a-z'}}">
|
||||||
<Icon icon="collection" /> Albums
|
<Icon icon="collection" /> Albums
|
||||||
</router-link>
|
</router-link>
|
||||||
|
|
||||||
|
@ -3,9 +3,17 @@
|
|||||||
<Spinner v-if="loading" />
|
<Spinner v-if="loading" />
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<div v-for="section in sections" :key="section.key" class="mb-4">
|
<div v-for="section in sections" :key="section.key" class="mb-4">
|
||||||
<template v-if="$data[section.key].length > 0">
|
<template v-if="result[section.key].length > 0">
|
||||||
<h1>{{ section.name }}</h1>
|
<h1>
|
||||||
<AlbumList :items="$data[section.key]" />
|
{{ section.name }}
|
||||||
|
<router-link
|
||||||
|
:to="{name: 'albums', params: {sort: section.key}}"
|
||||||
|
class="text-muted"
|
||||||
|
>
|
||||||
|
<Icon icon="chevron-compact-right" />
|
||||||
|
</router-link>
|
||||||
|
</h1>
|
||||||
|
<AlbumList :items="result[section.key]" />
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -23,36 +31,38 @@
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
loading: true as boolean,
|
loading: true as boolean,
|
||||||
recent: [] as Album[],
|
result: {
|
||||||
newest: [] as Album[],
|
'recently-added': [] as Album[],
|
||||||
frequent: [] as Album[],
|
'recently-played': [] as Album[],
|
||||||
|
'most-played': [] as Album[],
|
||||||
random: [] as Album[],
|
random: [] as Album[],
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
sections(): any[] {
|
sections(): any[] {
|
||||||
return [
|
return [
|
||||||
{ name: 'Recently added', key: 'newest' },
|
{ name: 'Recently added', key: 'recently-added' },
|
||||||
{ name: 'Recently played', key: 'recent' },
|
{ name: 'Recently played', key: 'recently-played' },
|
||||||
{ name: 'Most played', key: 'frequent' },
|
{ name: 'Most played', key: 'most-played' },
|
||||||
{ name: 'Random', key: 'random' },
|
{ name: 'Random', key: 'random' },
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
const size = 10
|
const size = 10
|
||||||
this.$api.getAlbums('newest', size).then(result => {
|
this.$api.getAlbums('recently-added', size).then(result => {
|
||||||
this.newest = result
|
this.result['recently-added'] = result
|
||||||
this.loading = false
|
this.loading = false
|
||||||
})
|
})
|
||||||
this.$api.getAlbums('recent', size).then(result => {
|
this.$api.getAlbums('recently-played', size).then(result => {
|
||||||
this.recent = result
|
this.result['recently-played'] = result
|
||||||
})
|
})
|
||||||
this.$api.getAlbums('frequent', size).then(result => {
|
this.$api.getAlbums('most-played', size).then(result => {
|
||||||
this.frequent = result
|
this.result['most-played'] = result
|
||||||
})
|
})
|
||||||
this.$api.getAlbums('random', 50).then(result => {
|
this.$api.getAlbums('random', 50).then(result => {
|
||||||
this.random = result
|
this.result.random = result
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<ul class="nav-underlined">
|
<ul class="nav-underlined">
|
||||||
<li v-for="{ value, text } in categories" :key="value">
|
<li v-for="{ value, text } in options" :key="value">
|
||||||
<router-link :to="{... $route, params: {... $route.params, sort: value }}">
|
<router-link :to="{... $route, params: {... $route.params, sort: value }}">
|
||||||
{{ text }}
|
{{ text }}
|
||||||
</router-link>
|
</router-link>
|
||||||
@ -17,14 +17,6 @@
|
|||||||
import AlbumList from './AlbumList.vue'
|
import AlbumList from './AlbumList.vue'
|
||||||
import { Album, AlbumSort } from '@/shared/api'
|
import { Album, AlbumSort } from '@/shared/api'
|
||||||
|
|
||||||
const categoryToSort = {
|
|
||||||
'a-z': 'alphabeticalByName',
|
|
||||||
'recently-added': 'newest',
|
|
||||||
'recently-played': 'recent',
|
|
||||||
'most-played': 'frequent',
|
|
||||||
random: 'random',
|
|
||||||
} as {[key: string]: AlbumSort}
|
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
components: {
|
components: {
|
||||||
AlbumList,
|
AlbumList,
|
||||||
@ -38,7 +30,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
categories() {
|
options() {
|
||||||
return [
|
return [
|
||||||
{ text: 'A-Z', value: 'a-z' },
|
{ text: 'A-Z', value: 'a-z' },
|
||||||
{ text: 'Recently added', value: 'recently-added' },
|
{ text: 'Recently added', value: 'recently-added' },
|
||||||
@ -51,9 +43,9 @@
|
|||||||
watch: {
|
watch: {
|
||||||
sort: {
|
sort: {
|
||||||
immediate: true,
|
immediate: true,
|
||||||
handler(value: string) {
|
handler(value: AlbumSort) {
|
||||||
this.albums = null
|
this.albums = null
|
||||||
this.$api.getAlbums(categoryToSort[value]).then(albums => {
|
this.$api.getAlbums(value).then(albums => {
|
||||||
this.albums = albums
|
this.albums = albums
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
import axios, { AxiosRequestConfig, AxiosInstance } from 'axios'
|
import axios, { AxiosRequestConfig, AxiosInstance } from 'axios'
|
||||||
import { AuthService } from '@/auth/service'
|
import { AuthService } from '@/auth/service'
|
||||||
|
|
||||||
export type AlbumSort = 'alphabeticalByName' | 'newest' | 'recent' | 'frequent' | 'random'
|
export type AlbumSort =
|
||||||
|
'a-z' |
|
||||||
|
'recently-added'|
|
||||||
|
'recently-played' |
|
||||||
|
'most-played' |
|
||||||
|
'random'
|
||||||
|
|
||||||
export interface Album {
|
export interface Album {
|
||||||
id: string
|
id: string
|
||||||
@ -123,8 +128,16 @@ export class API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getAlbums(sort: AlbumSort, size = 500): Promise<Album[]> {
|
async getAlbums(sort: AlbumSort, size = 500): Promise<Album[]> {
|
||||||
|
const type = {
|
||||||
|
'a-z': 'alphabeticalByName',
|
||||||
|
'recently-added': 'newest',
|
||||||
|
'recently-played': 'recent',
|
||||||
|
'most-played': 'frequent',
|
||||||
|
random: 'random',
|
||||||
|
}[sort]
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
type: sort,
|
type,
|
||||||
offset: '0',
|
offset: '0',
|
||||||
size: size,
|
size: size,
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
import {
|
import {
|
||||||
BIcon,
|
BIcon,
|
||||||
BIconCardText,
|
BIconCardText,
|
||||||
|
BIconChevronCompactRight,
|
||||||
BIconMusicNoteList,
|
BIconMusicNoteList,
|
||||||
BIconStar,
|
BIconStar,
|
||||||
BIconStarFill,
|
BIconStarFill,
|
||||||
@ -28,6 +29,7 @@
|
|||||||
components: {
|
components: {
|
||||||
BIcon,
|
BIcon,
|
||||||
BIconCardText,
|
BIconCardText,
|
||||||
|
BIconChevronCompactRight,
|
||||||
BIconMusicNoteList,
|
BIconMusicNoteList,
|
||||||
BIconStar,
|
BIconStar,
|
||||||
BIconStarFill,
|
BIconStarFill,
|
||||||
|
@ -41,14 +41,6 @@ export function setupRouter(auth: AuthService) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'albums',
|
name: 'albums',
|
||||||
path: '/albums',
|
|
||||||
redirect: {
|
|
||||||
name: 'albums-params',
|
|
||||||
params: { sort: 'a-z' }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'albums-params',
|
|
||||||
path: '/albums/:sort',
|
path: '/albums/:sort',
|
||||||
component: AlbumLibrary,
|
component: AlbumLibrary,
|
||||||
props: true
|
props: true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user