fix(web): refresh Home on explicit Home click
loadHomeData now takes a force flag; navigating to Home via a click (not back/forward) invalidates the home rows' API cache so they re-fetch and the random row re-randomizes — matching the Android re-tap behavior. CHANGELOG: note the Home-refresh fix under 1.0. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
211b8ec6c2
commit
58dacbabc3
3 files changed
+11
-9
No files matched your search
+8
-7
@@ -1,6 +1,6 @@
|
||||
import { S } from '../state.js';
|
||||
import { esc } from '../utils.js';
|
||||
import { api, apiCached, apiIsCached, coverUrl, fetchRomajiIndex, dispArtistById, dispAlbumName, cacheArtistSortNames } from '../api.js';
|
||||
import { api, apiCached, apiIsCached, invalidateApiCache, coverUrl, fetchRomajiIndex, dispArtistById, dispAlbumName, cacheArtistSortNames } from '../api.js';
|
||||
import { makeCard, makeAlbumCard, makeSongItem } from '../ui/components.js';
|
||||
import { playQueue } from '../player/player.js';
|
||||
// Circular — safe (called inside event handlers)
|
||||
@@ -32,7 +32,7 @@ const _greetN = [
|
||||
'Time to escape into music', 'Pick something great',
|
||||
];
|
||||
|
||||
export async function loadHomeData() {
|
||||
export async function loadHomeData(force = false) {
|
||||
const name = S.cfg.user || '';
|
||||
const g = name
|
||||
? `${_greetW[Math.floor(Math.random() * _greetW.length)]} ${name}`
|
||||
@@ -42,10 +42,10 @@ export async function loadHomeData() {
|
||||
|
||||
loadHeroCard();
|
||||
loadGenreSection();
|
||||
loadAlbumRow('home-newest', 'getAlbumList2', '&type=newest&size=20');
|
||||
loadAlbumRow('home-recent', 'getAlbumList2', '&type=recent&size=20');
|
||||
loadAlbumRow('home-random', 'getAlbumList2', '&type=random&size=20');
|
||||
loadAlbumRow('home-frequent', 'getAlbumList2', '&type=frequent&size=20');
|
||||
loadAlbumRow('home-newest', 'getAlbumList2', '&type=newest&size=20', force);
|
||||
loadAlbumRow('home-recent', 'getAlbumList2', '&type=recent&size=20', force);
|
||||
loadAlbumRow('home-random', 'getAlbumList2', '&type=random&size=20', force);
|
||||
loadAlbumRow('home-frequent', 'getAlbumList2', '&type=frequent&size=20', force);
|
||||
}
|
||||
|
||||
async function loadHeroCard() {
|
||||
@@ -194,9 +194,10 @@ export async function loadGenreDetail(g) {
|
||||
songs.forEach((s, i) => list.appendChild(makeSongItem(s, i, songs)));
|
||||
}
|
||||
|
||||
export async function loadAlbumRow(id, method, extra) {
|
||||
export async function loadAlbumRow(id, method, extra, force = false) {
|
||||
const c = document.getElementById(id);
|
||||
if(!c) return;
|
||||
if (force) invalidateApiCache(method, extra); // re-fetch (re-randomizes) on explicit Home click
|
||||
if (!apiIsCached(method, extra)) c.innerHTML = '<div class="spinner"></div>';
|
||||
try {
|
||||
const [r] = await Promise.all([
|
||||
|
||||
@@ -48,7 +48,7 @@ export function navigate(page, data=null) {
|
||||
if(['discover','new-releases','recommendations','random','spotify-importer'].includes(page)) switchNavMode('discover');
|
||||
else if(['home','artists','albums','starred','playlists'].includes(page)) switchNavMode('library');
|
||||
|
||||
if(page==='home') loadHomeData();
|
||||
if(page==='home') loadHomeData(!S._navJumping); // explicit Home click refreshes; back/forward keeps state
|
||||
if(page==='artists' && !document.getElementById('artists-grid').children.length) loadArtists();
|
||||
if(page==='albums' && !document.getElementById('albums-grid').children.length) loadAlbums();
|
||||
if(page==='starred') loadStarred();
|
||||
|
||||
Reference in new issue
Block a user