mirror of
https://github.com/pvrzz/atmosphere.git
synced 2026-11-29 05:22:26 +00:00
Home start page with shelves for recent, new, most played and playlists
This commit is contained in:
@@ -421,10 +421,10 @@ function bindShell() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function go(view) {
|
function go(view) {
|
||||||
if (state.view === view) return;
|
$$(".nav-item[data-nav]").forEach((b) => b.dataset.nav === view ? b.setAttribute("aria-current", "page") : b.removeAttribute("aria-current"));
|
||||||
|
if (state.view === view) return markLibNav();
|
||||||
state.view = view;
|
state.view = view;
|
||||||
$$(".view").forEach((v) => (v.hidden = v.dataset.view !== view));
|
$$(".view").forEach((v) => (v.hidden = v.dataset.view !== view));
|
||||||
$$(".nav-item[data-nav]").forEach((b) => b.dataset.nav === view ? b.setAttribute("aria-current", "page") : b.removeAttribute("aria-current"));
|
|
||||||
closeSaveMenu();
|
closeSaveMenu();
|
||||||
closeMenus();
|
closeMenus();
|
||||||
if (view !== "library") closeDrawers();
|
if (view !== "library") closeDrawers();
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -27,6 +27,7 @@
|
|||||||
<button class="icon-btn side-toggle" id="sideToggle" type="button" aria-label="Collapse sidebar" aria-expanded="true" data-tip="Collapse sidebar (Ctrl+B)"><span class="i" data-icon="layout-sidebar-left-collapse"></span></button>
|
<button class="icon-btn side-toggle" id="sideToggle" type="button" aria-label="Collapse sidebar" aria-expanded="true" data-tip="Collapse sidebar (Ctrl+B)"><span class="i" data-icon="layout-sidebar-left-collapse"></span></button>
|
||||||
</div>
|
</div>
|
||||||
<nav class="nav" aria-label="Main">
|
<nav class="nav" aria-label="Main">
|
||||||
|
<button class="nav-item" data-lib="home"><span class="i" data-icon="home"></span><span>Home</span></button>
|
||||||
<button class="nav-item" data-nav="get" aria-current="page"><span class="i" data-icon="cloud-download"></span><span>Get</span><kbd>Ctrl K</kbd></button>
|
<button class="nav-item" data-nav="get" aria-current="page"><span class="i" data-icon="cloud-download"></span><span>Get</span><kbd>Ctrl K</kbd></button>
|
||||||
<button class="nav-item" data-nav="downloads" id="navDownloads">
|
<button class="nav-item" data-nav="downloads" id="navDownloads">
|
||||||
<span class="nav-ring" aria-hidden="true"><svg viewBox="0 0 20 20"><circle class="track" cx="10" cy="10" r="8.5"/><circle class="fill" id="navRing" cx="10" cy="10" r="8.5"/></svg><span class="i" data-icon="download"></span></span>
|
<span class="nav-ring" aria-hidden="true"><svg viewBox="0 0 20 20"><circle class="track" cx="10" cy="10" r="8.5"/><circle class="fill" id="navRing" cx="10" cy="10" r="8.5"/></svg><span class="i" data-icon="download"></span></span>
|
||||||
|
|||||||
+75
-3
@@ -7,7 +7,7 @@ const Lib = {
|
|||||||
artists: new Map(),
|
artists: new Map(),
|
||||||
liked: new Set(),
|
liked: new Set(),
|
||||||
plays: {},
|
plays: {},
|
||||||
route: { name: "songs" },
|
route: { name: "home" },
|
||||||
back: [],
|
back: [],
|
||||||
filter: "",
|
filter: "",
|
||||||
sort: { key: "artist", dir: 1 },
|
sort: { key: "artist", dir: 1 },
|
||||||
@@ -120,7 +120,7 @@ async function loadLibrary() {
|
|||||||
if (!Lib.restored) {
|
if (!Lib.restored) {
|
||||||
Lib.restored = true;
|
Lib.restored = true;
|
||||||
Player.restore((id) => Lib.byId.get(id));
|
Player.restore((id) => Lib.byId.get(id));
|
||||||
if (Lib.songs.length && state.view === "get" && !state.collections.length) openLib("songs", null, false);
|
if (state.view === "get" && !state.collections.length) openLib("home", null, false);
|
||||||
} else {
|
} else {
|
||||||
Player.refreshTracks((id) => Lib.byId.get(id) || null);
|
Player.refreshTracks((id) => Lib.byId.get(id) || null);
|
||||||
}
|
}
|
||||||
@@ -758,6 +758,78 @@ function playlistView(root, name) {
|
|||||||
root.append(h("div", { class: "pad-x" }, h("p", { class: "muted small hint-line" }, p.linked ? "This is your own folder; songs in subfolders are included. Drag rows to reorder, saved in a playlist.m3u8 inside it." : "Drag rows to reorder. The order is saved in the folder's playlist.m3u8, so other players see it too."), trackList(tracks, { cover: true, playlist: p.name })));
|
root.append(h("div", { class: "pad-x" }, h("p", { class: "muted small hint-line" }, p.linked ? "This is your own folder; songs in subfolders are included. Drag rows to reorder, saved in a playlist.m3u8 inside it." : "Drag rows to reorder. The order is saved in the folder's playlist.m3u8, so other players see it too."), trackList(tracks, { cover: true, playlist: p.name })));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function greeting() {
|
||||||
|
const hr = new Date().getHours();
|
||||||
|
return hr < 5 ? "Up late" : hr < 12 ? "Good morning" : hr < 18 ? "Good afternoon" : "Good evening";
|
||||||
|
}
|
||||||
|
|
||||||
|
function trackCard(t) {
|
||||||
|
return h("div", { class: "card-tile", role: "button", tabindex: "0", "data-id": t.id, onclick: () => playList([t]), onkeydown: (e) => { if (e.key === "Enter") playList([t]); } },
|
||||||
|
h("div", { class: "tile-art" }, cover(t.art, "tile-img", t.title), h("button", { class: "tile-play", "aria-label": `Play ${t.title}`, onclick: (e) => { e.stopPropagation(); playList([t]); } }, icon("player-play-filled"))),
|
||||||
|
h("div", { class: "tile-title" }, t.title),
|
||||||
|
h("div", { class: "tile-sub" }, h("span", { class: "tile-kind" }, "Song"), ` · ${primaryArtist(t.artist)}`));
|
||||||
|
}
|
||||||
|
|
||||||
|
function playlistCard(p) {
|
||||||
|
const tracks = p.order.map((id) => Lib.byId.get(id)).filter(Boolean);
|
||||||
|
const arts = [...new Set(tracks.map((t) => t.art).filter(Boolean))].slice(0, 4);
|
||||||
|
const art = arts.length >= 4 ? h("div", { class: "tile-img tile-mosaic" }, ...arts.map((k) => cover(k, ""))) : arts.length ? cover(arts[0], "tile-img", p.name) : h("div", { class: "tile-img ph" }, icon(p.linked ? "folder" : "playlist"));
|
||||||
|
return h("div", { class: "card-tile", role: "button", tabindex: "0", "data-playlist": p.name, onclick: () => openLib("playlist", p.name), onkeydown: (e) => { if (e.key === "Enter") openLib("playlist", p.name); } },
|
||||||
|
h("div", { class: "tile-art" }, art, tracks.length ? h("button", { class: "tile-play", "aria-label": `Play ${p.name}`, onclick: (e) => { e.stopPropagation(); playList(tracks); } }, icon("player-play-filled")) : null),
|
||||||
|
h("div", { class: "tile-title" }, p.name),
|
||||||
|
h("div", { class: "tile-sub" }, h("span", { class: "tile-kind" }, "Playlist"), ` · ${plural(tracks.length, "song")}`));
|
||||||
|
}
|
||||||
|
|
||||||
|
function contextsFrom(tracks, limit) {
|
||||||
|
const out = [];
|
||||||
|
const seen = new Set();
|
||||||
|
for (const t of tracks) {
|
||||||
|
const a = t.album ? Lib.albums.get(`${lnorm(t.albumArtist || primaryArtist(t.artist))}|${lnorm(t.album)}`) : null;
|
||||||
|
const key = a ? `a:${a.key}` : `t:${t.id}`;
|
||||||
|
if (seen.has(key)) continue;
|
||||||
|
seen.add(key);
|
||||||
|
out.push(a && a.tracks.length > 1 ? albumCard(a) : trackCard(t));
|
||||||
|
if (out.length >= limit) break;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function shelf(title, cards, more) {
|
||||||
|
if (!cards.length) return null;
|
||||||
|
return h("section", { class: "shelf-sec" },
|
||||||
|
h("div", { class: "sec-row" }, h("h2", { class: "sec" }, title), more ? h("button", { class: "link muted small", onclick: more }, "Show all") : null),
|
||||||
|
h("div", { class: "grid shelf" }, ...cards));
|
||||||
|
}
|
||||||
|
|
||||||
|
function homeView(root) {
|
||||||
|
const songs = Lib.songs;
|
||||||
|
root.append(
|
||||||
|
h("header", { class: "home-head" },
|
||||||
|
h("div", {},
|
||||||
|
h("h1", {}, greeting()),
|
||||||
|
h("p", { class: "view-sub" }, songs.length ? [plural(songs.length, "song"), plural(Lib.albums.size, "album"), plural(Lib.artists.size, "artist")].join(" · ") : "Let's get some music in here.")),
|
||||||
|
songs.length
|
||||||
|
? h("div", { class: "row home-quick" },
|
||||||
|
h("button", { class: "btn primary", onclick: () => playList(songs, Math.floor(Math.random() * songs.length), true) }, icon("arrows-shuffle"), "Shuffle everything"),
|
||||||
|
Lib.liked.size ? h("button", { class: "btn", onclick: () => openLib("liked") }, icon("heart"), "Liked songs") : null,
|
||||||
|
h("button", { class: "btn ghost", onclick: () => openLib("stats") }, icon("chart-bar"), "Your stats"))
|
||||||
|
: null)
|
||||||
|
);
|
||||||
|
if (!songs.length) return root.append(emptyLibrary());
|
||||||
|
const last = Lib.data?.lastPlayed || {};
|
||||||
|
const recent = songs.filter((t) => last[t.id]).sort((a, b) => last[b.id] - last[a.id]);
|
||||||
|
const added = [...songs].sort((a, b) => (b.added || 0) - (a.added || 0));
|
||||||
|
const top = songs.filter((t) => Lib.plays[t.id]).sort((a, b) => (Lib.plays[b.id] || 0) - (Lib.plays[a.id] || 0)).slice(0, 5);
|
||||||
|
const lists = (Lib.data?.playlists || []).filter((p) => !p.missing && p.order.length);
|
||||||
|
const body = h("div", { class: "pad-x sections home" },
|
||||||
|
shelf("Jump back in", contextsFrom(recent, 12)),
|
||||||
|
shelf("Recently added", contextsFrom(added, 12), () => { Lib.sort = { key: "added", dir: 1 }; openLib("songs"); }),
|
||||||
|
top.length ? h("section", { class: "shelf-sec" }, h("div", { class: "sec-row" }, h("h2", { class: "sec" }, "On repeat"), h("button", { class: "link muted small", onclick: () => { Lib.sort = { key: "plays", dir: 1 }; openLib("songs"); } }, "Show all")), trackList(top, { cover: true, list: top })) : null,
|
||||||
|
shelf("Your playlists", lists.slice(0, 12).map(playlistCard)));
|
||||||
|
if (!recent.length && !top.length) body.prepend(h("p", { class: "muted home-hint" }, "Play a few songs and this page fills up with your favourites."));
|
||||||
|
root.append(body);
|
||||||
|
}
|
||||||
|
|
||||||
function likedView(root) {
|
function likedView(root) {
|
||||||
const list = filtered(Lib.songs.filter((t) => Lib.liked.has(t.id)));
|
const list = filtered(Lib.songs.filter((t) => Lib.liked.has(t.id)));
|
||||||
root.append(libHead("Liked songs", plural(list.length, "song"), playBtns(list), { search: true, onSearch: () => renderLib(true) }));
|
root.append(libHead("Liked songs", plural(list.length, "song"), playBtns(list), { search: true, onSearch: () => renderLib(true) }));
|
||||||
@@ -774,7 +846,7 @@ function renderLib(soft = false) {
|
|||||||
root.replaceChildren();
|
root.replaceChildren();
|
||||||
Lib.drawSongs = null;
|
Lib.drawSongs = null;
|
||||||
const r = Lib.route;
|
const r = Lib.route;
|
||||||
({ songs: songsView, albums: albumsView, album: (x) => albumView(x, r.id), artists: artistsView, artist: (x) => artistView(x, r.id), playlist: (x) => playlistView(x, r.id), liked: likedView, stats: statsView }[r.name] || songsView)(root);
|
({ songs: songsView, albums: albumsView, album: (x) => albumView(x, r.id), artists: artistsView, artist: (x) => artistView(x, r.id), playlist: (x) => playlistView(x, r.id), liked: likedView, stats: statsView, home: homeView }[r.name] || homeView)(root);
|
||||||
scroller.scrollTop = y;
|
scroller.scrollTop = y;
|
||||||
if (focusSearch) {
|
if (focusSearch) {
|
||||||
const s = $(".lib-search");
|
const s = $(".lib-search");
|
||||||
|
|||||||
@@ -1070,3 +1070,17 @@ body.mini-mode > *:not(#mini):not(.toasts):not(.modal-wrap):not(script) { displa
|
|||||||
.slider-row { display: flex; align-items: center; gap: var(--s3); flex-shrink: 0; }
|
.slider-row { display: flex; align-items: center; gap: var(--s3); flex-shrink: 0; }
|
||||||
.slider-row .range { width: 180px; }
|
.slider-row .range { width: 180px; }
|
||||||
.slider-val { min-width: 34px; text-align: right; font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
|
.slider-val { min-width: 34px; text-align: right; font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
|
||||||
|
|
||||||
|
/* home */
|
||||||
|
.home-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s5); flex-wrap: wrap; padding: var(--s8) var(--s8) var(--s5); }
|
||||||
|
.home-head h1 { font: 700 30px/1.15 var(--font-display); letter-spacing: -0.02em; margin: 0; }
|
||||||
|
.home-quick { flex-wrap: wrap; }
|
||||||
|
.home { display: grid; gap: var(--s6); padding-bottom: var(--s8); }
|
||||||
|
.home-hint { margin: 0; }
|
||||||
|
.sec-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }
|
||||||
|
.sec-row .sec { margin: 0; }
|
||||||
|
.grid.shelf { grid-template-rows: auto; grid-auto-rows: 0; overflow: hidden; row-gap: 0; padding: var(--s2); margin: calc(var(--s2) * -1); }
|
||||||
|
.tile-mosaic { display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; }
|
||||||
|
.tile-mosaic img, .tile-mosaic .cover { width: 100%; height: 100%; object-fit: cover; border-radius: 0; }
|
||||||
|
.tile-img.ph { display: grid; place-items: center; background: var(--surface); color: var(--text-3); }
|
||||||
|
.tile-img.ph .i svg { width: 36px; height: 36px; }
|
||||||
|
|||||||
Reference in New Issue
Block a user