feat: add sort filter chips to albums and favorites views
This commit is contained in:
1 parent
751cc05b89
commit
47f1605965
4 files changed
+40
-6
No files matched your search
+19
-4
@@ -154,11 +154,16 @@ export async function loadArtists() {
|
||||
}
|
||||
|
||||
// ─── ALBUMS ───
|
||||
export async function loadAlbums() {
|
||||
let _albumSort = 'alphabeticalByName';
|
||||
|
||||
export async function loadAlbums(type = _albumSort) {
|
||||
_albumSort = type;
|
||||
document.querySelectorAll('#albums-sort-chips .sort-chip').forEach(c =>
|
||||
c.classList.toggle('active', c.dataset.sort === type));
|
||||
const g = document.getElementById('albums-grid');
|
||||
g.innerHTML = '<div class="spinner"></div>';
|
||||
try {
|
||||
const r = await api('getAlbumList2', '&type=alphabeticalByName&size=500');
|
||||
const r = await api('getAlbumList2', `&type=${type}&size=500`);
|
||||
g.innerHTML = '';
|
||||
(r.albumList2?.album || []).forEach(a => g.appendChild(makeAlbumCard(a)));
|
||||
} catch(e) { g.innerHTML = `<p style="color:var(--danger)">${e.message}</p>`; }
|
||||
@@ -632,12 +637,22 @@ export async function quickPlayAlbum(a) {
|
||||
}
|
||||
|
||||
// ─── STARRED / RANDOM ───
|
||||
export async function loadStarred() {
|
||||
let _starredSort = 'newest';
|
||||
|
||||
export async function loadStarred(sort = _starredSort) {
|
||||
_starredSort = sort;
|
||||
document.querySelectorAll('#starred-sort-chips .sort-chip').forEach(c =>
|
||||
c.classList.toggle('active', c.dataset.sort === sort));
|
||||
const el = document.getElementById('starred-songs');
|
||||
el.innerHTML = '<div class="spinner"></div>';
|
||||
try {
|
||||
const r = await api('getStarred2');
|
||||
const songs = (r.starred2?.song || []).map(s => ({...s,_starred:true}));
|
||||
let songs = (r.starred2?.song || []).map(s => ({...s, _starred: true}));
|
||||
if (sort === 'newest') songs.sort((a, b) => new Date(b.starred||0) - new Date(a.starred||0));
|
||||
else if (sort === 'oldest') songs.sort((a, b) => new Date(a.starred||0) - new Date(b.starred||0));
|
||||
else if (sort === 'az') songs.sort((a, b) => (a.title||'').localeCompare(b.title||''));
|
||||
else if (sort === 'artist') songs.sort((a, b) => (a.artist||'').localeCompare(b.artist||''));
|
||||
else if (sort === 'plays') songs.sort((a, b) => (b.playCount||0) - (a.playCount||0));
|
||||
el.innerHTML = '';
|
||||
if(!songs.length) { el.innerHTML = '<div class="empty-state"><div class="icon">⭐</div><p>Noch keine Favoriten</p></div>'; return; }
|
||||
songs.forEach((s,i) => el.appendChild(makeSongItem(s, i, songs)));
|
||||
|
||||
Reference in new issue
Block a user