feat: allow sorting by date added (#1631)

This commit is contained in:
Phan An 2022-12-15 22:59:19 +07:00 committed by GitHub
parent cb84f14f34
commit e8e2c2db75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 2 deletions

View file

@ -22,12 +22,21 @@ class SongRepository extends Repository
'title' => 'songs.title', 'title' => 'songs.title',
'track' => 'songs.track', 'track' => 'songs.track',
'length' => 'songs.length', 'length' => 'songs.length',
'created_at' => 'songs.created_at',
'disc' => 'songs.disc', 'disc' => 'songs.disc',
'artist_name' => 'artists.name', 'artist_name' => 'artists.name',
'album_name' => 'albums.name', 'album_name' => 'albums.name',
]; ];
private const VALID_SORT_COLUMNS = ['songs.title', 'songs.track', 'songs.length', 'artists.name', 'albums.name']; private const VALID_SORT_COLUMNS = [
'songs.title',
'songs.track',
'songs.length',
'songs.created_at',
'artists.name',
'albums.name',
];
private const DEFAULT_QUEUE_LIMIT = 500; private const DEFAULT_QUEUE_LIMIT = 500;
public function getOneByPath(string $path): ?Song public function getOneByPath(string $path): ?Song

View file

@ -53,6 +53,10 @@ const menuItems: { label: string, field: SongListSortField }[] = [
{ {
label: 'Time', label: 'Time',
field: 'length' field: 'length'
},
{
label: 'Date Added',
field: 'created_at'
} }
] ]

View file

@ -21,9 +21,13 @@ interface Plyr {
media: HTMLMediaElement media: HTMLMediaElement
restart (): void restart (): void
play (): void play (): void
pause (): void pause (): void
seek (position: number): void seek (position: number): void
setVolume (volume: number): void setVolume (volume: number): void
} }
@ -351,7 +355,7 @@ interface SongListConfig {
reorderable: boolean reorderable: boolean
} }
type SongListSortField = keyof Pick<Song, 'track' | 'disc' | 'title' | 'album_name' | 'length' | 'artist_name'> type SongListSortField = keyof Pick<Song, 'track' | 'disc' | 'title' | 'album_name' | 'length' | 'artist_name' | 'created_at'>
type SortOrder = 'asc' | 'desc' type SortOrder = 'asc' | 'desc'