From ffb16656e7d55dd44303ab69679858e0e6e3e5ca Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Sun, 18 Jan 2026 15:52:31 -0600 Subject: [PATCH] feat(phase4.7): implement history-aware favorites tab navigation - Extended navigationStore with FavoritesTab state tracking - Added setFavoritesTab() to push tab changes to history - Modified navigateTo() to support favorites sub-navigation - Wired handleTabChange() to call setFavoritesTab() - Synced activeTab with navigation store via currentTab prop - Back button now returns to correct Favorites tab cp --- src/lib/components/views/FavoritesView.svelte | 15 +++++- src/lib/stores/navigationStore.ts | 50 ++++++++++++++++++- src/routes/+page.svelte | 5 +- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/lib/components/views/FavoritesView.svelte b/src/lib/components/views/FavoritesView.svelte index 406e52b10..4e00e81d0 100644 --- a/src/lib/components/views/FavoritesView.svelte +++ b/src/lib/components/views/FavoritesView.svelte @@ -8,6 +8,7 @@ import FavoritesEditModal from '../FavoritesEditModal.svelte'; import { type DownloadStatus } from '$lib/stores/downloadState'; import { setPlaybackContext } from '$lib/stores/playbackContextStore'; + import { setFavoritesTab } from '$lib/stores/navigationStore'; import type { FavoritesPreferences } from '$lib/types'; interface FavoriteAlbum { @@ -76,6 +77,7 @@ onTrackRemoveDownload?: (trackId: number) => void; getTrackDownloadStatus?: (trackId: number) => { status: DownloadStatus; progress: number }; onPlaylistSelect?: (playlistId: number) => void; + currentTab?: TabType; // For syncing with navigation store } interface DisplayTrack { @@ -120,12 +122,20 @@ onTrackDownload, onTrackRemoveDownload, getTrackDownloadStatus, - onPlaylistSelect + onPlaylistSelect, + currentTab }: Props = $props(); type TabType = 'tracks' | 'albums' | 'artists' | 'playlists'; let activeTab = $state('tracks'); + // Sync activeTab with navigation store when parent passes currentTab + $effect(() => { + if (currentTab && currentTab !== activeTab) { + activeTab = currentTab; + } + }); + const tabLabels: Record = { tracks: 'Tracks', albums: 'Albums', @@ -427,6 +437,9 @@ } function handleTabChange(tab: TabType) { + // Push to navigation history for back button support + setFavoritesTab(tab); + activeTab = tab; showAlbumGroupMenu = false; showTrackGroupMenu = false; diff --git a/src/lib/stores/navigationStore.ts b/src/lib/stores/navigationStore.ts index d7a067c47..4f807b98c 100644 --- a/src/lib/stores/navigationStore.ts +++ b/src/lib/stores/navigationStore.ts @@ -7,6 +7,7 @@ */ export type ViewType = 'home' | 'search' | 'library' | 'library-album' | 'settings' | 'album' | 'artist' | 'playlist' | 'playlist-manager' | 'favorites'; +export type FavoritesTab = 'tracks' | 'albums' | 'artists' | 'playlists'; // Navigation state let activeView: ViewType = 'home'; @@ -19,6 +20,9 @@ let selectedPlaylistId: number | null = null; // Selected local album ID (for library-album view) let selectedLocalAlbumId: string | null = null; +// Selected Favorites tab (for history-aware navigation) +let selectedFavoritesTab: FavoritesTab = 'tracks'; + // Listeners const listeners = new Set<() => void>(); @@ -42,11 +46,30 @@ export function subscribe(listener: () => void): () => void { /** * Navigate to a view */ -export function navigateTo(view: ViewType): void { +export function navigateTo(view: ViewType, favoritesTab?: FavoritesTab): void { + // For favorites view, allow sub-navigation by tracking tab changes + if (view === 'favorites' && favoritesTab && activeView === 'favorites' && favoritesTab !== selectedFavoritesTab) { + // Changing tabs within Favorites - push to history + viewHistory = [...viewHistory, view]; + selectedFavoritesTab = favoritesTab; + notifyListeners(); + return; + } + if (view !== activeView) { viewHistory = [...viewHistory, view]; forwardHistory = []; activeView = view; + + // Update favorites tab if specified + if (view === 'favorites' && favoritesTab) { + selectedFavoritesTab = favoritesTab; + } + + notifyListeners(); + } else if (view === 'favorites' && favoritesTab && favoritesTab !== selectedFavoritesTab) { + // Same view but different tab - just update tab without history + selectedFavoritesTab = favoritesTab; notifyListeners(); } } @@ -152,6 +175,29 @@ export function getSelectedLocalAlbumId(): string | null { return selectedLocalAlbumId; } +// ============ Favorites Tab Selection ============ + +/** + * Get selected Favorites tab + */ +export function getSelectedFavoritesTab(): FavoritesTab { + return selectedFavoritesTab; +} + +/** + * Set selected Favorites tab (creates history entry if already on favorites view) + */ +export function setFavoritesTab(tab: FavoritesTab): void { + if (activeView === 'favorites' && tab !== selectedFavoritesTab) { + // Push to history to allow back navigation + viewHistory = [...viewHistory, 'favorites']; + selectedFavoritesTab = tab; + notifyListeners(); + } else if (activeView !== 'favorites') { + selectedFavoritesTab = tab; + } +} + // ============ Getters ============ export function getActiveView(): ViewType { @@ -166,6 +212,7 @@ export interface NavigationState { forwardHistory: ViewType[]; selectedPlaylistId: number | null; selectedLocalAlbumId: string | null; + selectedFavoritesTab: FavoritesTab; canGoBack: boolean; canGoForward: boolean; } @@ -177,6 +224,7 @@ export function getNavigationState(): NavigationState { forwardHistory: [...forwardHistory], selectedPlaylistId, selectedLocalAlbumId, + selectedFavoritesTab, canGoBack: viewHistory.length > 1, canGoForward: forwardHistory.length > 0 }; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index d0af5674c..335e1886a 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -80,8 +80,10 @@ goForward as navGoForward, selectPlaylist, getNavigationState, + getSelectedFavoritesTab, type ViewType, - type NavigationState + type NavigationState, + type FavoritesTab } from '$lib/stores/navigationStore'; // Player state management @@ -2194,6 +2196,7 @@ onTrackRemoveDownload={handleTrackRemoveDownload} getTrackDownloadStatus={getTrackDownloadStatus} onPlaylistSelect={selectPlaylist} + currentTab={getSelectedFavoritesTab()} /> {/if} {:else if activeView === 'playlist-manager'}