mirror of
https://github.com/koel/koel
synced 2025-02-17 13:58:28 +00:00
chore: some type improvements
This commit is contained in:
parent
e2b5066e08
commit
d4bf3cfb6c
4 changed files with 12 additions and 7 deletions
|
@ -80,7 +80,7 @@ export const albumStore = {
|
|||
},
|
||||
|
||||
async paginate (page: number) {
|
||||
const resource = await http.get<PaginatorResource>(`albums?page=${page}`)
|
||||
const resource = await http.get<PaginatorResource<Album>>(`albums?page=${page}`)
|
||||
this.state.albums = unionBy(this.state.albums, this.syncWithVault(resource.data), 'id')
|
||||
|
||||
return resource.links.next ? ++resource.meta.current_page : null
|
||||
|
|
|
@ -70,7 +70,7 @@ export const artistStore = {
|
|||
},
|
||||
|
||||
async paginate (page: number) {
|
||||
const resource = await http.get<PaginatorResource>(`artists?page=${page}`)
|
||||
const resource = await http.get<PaginatorResource<Artist>>(`artists?page=${page}`)
|
||||
this.state.artists = unionBy(this.state.artists, this.syncWithVault(resource.data), 'id')
|
||||
|
||||
return resource.links.next ? ++resource.meta.current_page : null
|
||||
|
|
|
@ -66,7 +66,8 @@ export const songStore = {
|
|||
},
|
||||
|
||||
byAlbum (album: Album) {
|
||||
return Array.from(this.vault.values()).filter(playable => isSong(playable) && playable.album_id === album.id)
|
||||
return Array.from(this.vault.values())
|
||||
.filter(playable => isSong(playable) && playable.album_id === album.id) as Song[]
|
||||
},
|
||||
|
||||
async resolve (id: string) {
|
||||
|
@ -231,7 +232,11 @@ export const songStore = {
|
|||
|
||||
async paginateForGenre (genre: Genre | Genre['name'], params: GenreSongListPaginateParams) {
|
||||
const name = typeof genre === 'string' ? genre : genre.name
|
||||
const resource = await http.get<PaginatorResource>(`genres/${name}/songs?${new URLSearchParams(params).toString()}`)
|
||||
|
||||
const resource = await http.get<PaginatorResource<Song>>(
|
||||
`genres/${name}/songs?${new URLSearchParams(params).toString()}`
|
||||
)
|
||||
|
||||
const songs = this.syncWithVault(resource.data)
|
||||
|
||||
return {
|
||||
|
@ -246,7 +251,7 @@ export const songStore = {
|
|||
},
|
||||
|
||||
async paginate (params: SongListPaginateParams) {
|
||||
const resource = await http.get<PaginatorResource>(`songs?${new URLSearchParams(params).toString()}`)
|
||||
const resource = await http.get<PaginatorResource<Song>>(`songs?${new URLSearchParams(params).toString()}`)
|
||||
this.state.songs = unionBy(this.state.songs, this.syncWithVault(resource.data), 'id')
|
||||
|
||||
return resource.links.next ? ++resource.meta.current_page : null
|
||||
|
|
4
resources/assets/js/types.d.ts
vendored
4
resources/assets/js/types.d.ts
vendored
|
@ -479,8 +479,8 @@ type MoveType = 'before' | 'after'
|
|||
|
||||
type MethodOf<T> = { [K in keyof T]: T[K] extends Closure ? K : never; }[keyof T]
|
||||
|
||||
interface PaginatorResource {
|
||||
data: any[]
|
||||
interface PaginatorResource<T> {
|
||||
data: T[]
|
||||
links: {
|
||||
next: string | null
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue