mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
feat: library browse navigation — restore filters, scroll, and search on back (#936)
* feat(albums): restore scroll position when returning from album detail Save in-page scroll and grid depth when opening an album from All Albums, then on browser back restore filters, preload enough rows, and apply scroll before revealing the grid to avoid a visible jump from the top. * feat(albums): smart back navigation and restore browse session on return Remember the originating route when opening album detail, restore All Albums filters/scroll on back (including explicit returnTo navigation), hide the grid until scroll is applied, and fix filters being cleared after albumBrowseRestore state is stripped from the location. * feat(search): restore Advanced Search session when returning from album Stash filters and results when leaving /search/advanced for album detail, then restore them on back navigation (POP or returnTo with advancedSearchRestore). * feat(search): restore Advanced Search album row scroll on return from album Save horizontal scrollLeft when opening an album from Advanced Search and reapply it via AlbumRow on return; keep main viewport at top. Add snapshot helpers and session stash fields; extend AlbumRow with restoreScrollLeft. * feat(search): restore Advanced Search session scroll and artist return path Save filters, main scroll, and album-row scroll when leaving to album or artist; restore without flash via hidden-until-ready. Add useNavigateToArtist, restoreMainViewportScroll helper, and AppShell scroll reset only on pathname change. * feat(search): speed up Advanced Search back restore and year-only queries Reveal the page right after sync scroll instead of blocking on full viewport and album-row restore. Retry local index without the ready gate during sync; use open-ended byYear params on network fallback, matching All Albums browse. * feat(search): restore Advanced Search artist row scroll on back Save leave snapshot when opening artist from ArtistCardLocal, persist artistRowScrollLeft in session stash, and keep row restore targets in refs so horizontal scroll survives finishLeaveRestoreUi like vertical scrollTop. * feat(nav): route mouse back on album/artist detail like UI back Trap history popstate when returnTo is set and call navigateAlbumDetailBack so browser/mouse back restores browse/search session the same way as the header button. * feat(artists): restore browse filters and scroll on back from artist detail Persist Artists page filters, view settings, and vertical scroll when opening an artist and returning via UI or mouse back, matching All Albums behavior. * feat(search): unify quick and advanced search; fix LiveSearch dismiss on Enter Serve /search and /search/advanced from one page with shared session restore and scroll snapshot. Reset live search overlay state when navigating to full search so the dropdown does not linger or reopen. * feat(tracks): unify with search session and restore scroll on back Route /tracks through AdvancedSearch with shared leave snapshot, song browse stash, and main-viewport scroll restore when returning from album or artist detail. Wait for hero/rails layout before applying scroll. * refactor(search): rename AdvancedSearch page to SearchBrowsePage The shared route shell serves /search, /search/advanced, and /tracks; rename the page component and refresh stale file references in comments. * feat(albums): restore New Releases and Random Albums on back from detail Unify album grid leave-restore with surface-scoped session stash, live scroll snapshot sync, and in-page scroll for Random Albums. Keep the same random batch when returning from album detail; Refresh fetches anew and scrolls up. * docs: add CHANGELOG and credits for PR #936
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { onInvoke } from '@/test/mocks/tauri';
|
||||
import { useAuthStore } from '@/store/authStore';
|
||||
import { useLibraryIndexStore } from '@/store/libraryIndexStore';
|
||||
@@ -6,8 +6,11 @@ import {
|
||||
resolveTrackCoverArtId,
|
||||
runLocalAdvancedSearch,
|
||||
runLocalSongBrowse,
|
||||
runNetworkAdvancedYearAlbums,
|
||||
trackToSong,
|
||||
tryRunLocalAdvancedSearch,
|
||||
} from './advancedSearchLocal';
|
||||
import * as albumBrowseNetwork from './albumBrowseNetwork';
|
||||
|
||||
const opts = (over: Partial<Parameters<typeof runLocalAdvancedSearch>[1]> = {}) => ({
|
||||
query: '',
|
||||
@@ -263,3 +266,60 @@ describe('runLocalSongBrowse', () => {
|
||||
expect(await runLocalSongBrowse('s1', 0, 50)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('tryRunLocalAdvancedSearch', () => {
|
||||
beforeEach(() => {
|
||||
useLibraryIndexStore.setState({ masterEnabled: true });
|
||||
});
|
||||
|
||||
it('retries without the ready gate when sync is still in progress', async () => {
|
||||
onInvoke('library_get_status', () => ({
|
||||
serverId: 's1',
|
||||
libraryScope: '',
|
||||
syncPhase: 'initial_sync',
|
||||
localTrackCount: 100,
|
||||
serverTrackCount: 1000,
|
||||
capabilityFlags: 0,
|
||||
libraryTier: 'unknown',
|
||||
syncedAt: 0,
|
||||
}));
|
||||
let searchCalls = 0;
|
||||
onInvoke('library_advanced_search', () => {
|
||||
searchCalls += 1;
|
||||
return {
|
||||
source: 'local',
|
||||
artists: [],
|
||||
albums: [],
|
||||
tracks: [],
|
||||
totals: { artists: 0, albums: 0, tracks: 0 },
|
||||
appliedFilters: ['year'],
|
||||
};
|
||||
});
|
||||
const res = await tryRunLocalAdvancedSearch('s1', opts({ yearFrom: '2020' }), 100);
|
||||
expect(res).not.toBeNull();
|
||||
expect(searchCalls).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('runNetworkAdvancedYearAlbums', () => {
|
||||
it('passes open-ended year bounds to album browse (not 1900…now defaults)', async () => {
|
||||
const spy = vi.spyOn(albumBrowseNetwork, 'fetchAlbumBrowseNetwork').mockResolvedValue({
|
||||
albums: [{
|
||||
id: 'a1',
|
||||
name: 'Al',
|
||||
artist: 'Ar',
|
||||
artistId: 'ar1',
|
||||
songCount: 1,
|
||||
duration: 100,
|
||||
}],
|
||||
hasMore: false,
|
||||
});
|
||||
await runNetworkAdvancedYearAlbums(opts({ yearTo: '1990' }), 100);
|
||||
expect(spy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ year: { to: 1990 } }),
|
||||
0,
|
||||
100,
|
||||
);
|
||||
spy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Advanced Search against the local library index (spec §5.13 / F2).
|
||||
*
|
||||
* Maps the AdvancedSearch UI inputs to a `library_advanced_search` request and
|
||||
* Maps the SearchBrowsePage filter inputs to a `library_advanced_search` request and
|
||||
* the response back to the Subsonic shapes the existing rows render. The sync
|
||||
* engine stores each entity's original Subsonic JSON in `rawJson` (ADR-7), so
|
||||
* that's preferred verbatim; the flat hot columns are a fallback when a row's
|
||||
@@ -23,12 +23,17 @@ import {
|
||||
import type { SubsonicAlbum, SubsonicArtist, SubsonicSong } from '../../api/subsonicTypes';
|
||||
import { search } from '../../api/subsonicSearch';
|
||||
import { libraryScopeForServer } from '../../api/subsonicClient';
|
||||
import { fetchAlbumBrowseNetwork } from './albumBrowseNetwork';
|
||||
import type { AlbumBrowseQuery } from './albumBrowseTypes';
|
||||
import { resolveAlbumYearBounds } from './albumYearFilter';
|
||||
import { libraryIsReady } from './libraryReady';
|
||||
import { logLibrarySearch, timed } from './libraryDevLog';
|
||||
import { isLosslessSuffix } from './losslessFormats';
|
||||
import { albumIsCompilation } from './albumCompilation';
|
||||
import { OXIMEDIA_MOOD_SEARCH_ENABLED } from './trackEnrichment';
|
||||
|
||||
export const ADVANCED_SEARCH_YEAR_ALBUM_LIMIT = 100;
|
||||
|
||||
export type AdvancedResultType = 'all' | 'artists' | 'albums' | 'songs';
|
||||
|
||||
/** UI opts for Advanced Search — BPM/mood filters require local index. */
|
||||
@@ -238,7 +243,7 @@ export function artistToArtist(ar: LibraryArtistDto): SubsonicArtist {
|
||||
}
|
||||
|
||||
/**
|
||||
* Network search3 path for Advanced Search free-text (mirrors AdvancedSearch.tsx filters).
|
||||
* Network search3 path for Advanced Search free-text (mirrors SearchBrowsePage.tsx filters).
|
||||
*/
|
||||
export async function runNetworkAdvancedTextSearch(
|
||||
opts: LocalSearchOpts,
|
||||
@@ -393,3 +398,46 @@ export async function loadMoreLocalSongs(
|
||||
const resp = await libraryAdvancedSearch(req);
|
||||
return resp.tracks.map(trackToSong);
|
||||
}
|
||||
|
||||
/** Local index first; retry without the ready gate when sync is still catching up. */
|
||||
export async function tryRunLocalAdvancedSearch(
|
||||
serverId: string | null | undefined,
|
||||
opts: LocalSearchOpts,
|
||||
songsLimit: number,
|
||||
suppressLog = false,
|
||||
): Promise<LocalAdvancedSearchPage | null> {
|
||||
const readyPage = await runLocalAdvancedSearch(
|
||||
serverId,
|
||||
opts,
|
||||
songsLimit,
|
||||
false,
|
||||
true,
|
||||
suppressLog,
|
||||
);
|
||||
if (readyPage) return readyPage;
|
||||
return runLocalAdvancedSearch(serverId, opts, songsLimit, true, true, suppressLog);
|
||||
}
|
||||
|
||||
function yearOnlyAlbumBrowseQuery(opts: LocalSearchOpts): AlbumBrowseQuery | null {
|
||||
const { active, bounds } = resolveAlbumYearBounds(opts.yearFrom, opts.yearTo);
|
||||
if (!active) return null;
|
||||
return {
|
||||
sort: 'alphabeticalByName',
|
||||
genres: [],
|
||||
year: bounds,
|
||||
losslessOnly: !!opts.losslessOnly,
|
||||
starredOnly: false,
|
||||
compFilter: 'all',
|
||||
};
|
||||
}
|
||||
|
||||
/** Network fallback for year-only Advanced Search albums (open-ended year bounds). */
|
||||
export async function runNetworkAdvancedYearAlbums(
|
||||
opts: LocalSearchOpts,
|
||||
pageSize = ADVANCED_SEARCH_YEAR_ALBUM_LIMIT,
|
||||
): Promise<SubsonicAlbum[]> {
|
||||
const query = yearOnlyAlbumBrowseQuery(opts);
|
||||
if (!query) return [];
|
||||
const page = await fetchAlbumBrowseNetwork(query, 0, pageSize);
|
||||
return page.albums;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Browse-page text search — local index vs network race (LiveSearch / AdvancedSearch pattern).
|
||||
* Browse-page text search — local index vs network race (LiveSearch / SearchBrowsePage pattern).
|
||||
*/
|
||||
import { getStarred } from '../../api/subsonicStarRating';
|
||||
import { search, searchSongsPaged } from '../../api/subsonicSearch';
|
||||
|
||||
Reference in New Issue
Block a user