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
This commit is contained in:
1 parent
902705f47f
commit
ffb16656e7
3 files changed
+67
-3
No files matched your search
@@ -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<TabType>('tracks');
|
||||
|
||||
// Sync activeTab with navigation store when parent passes currentTab
|
||||
$effect(() => {
|
||||
if (currentTab && currentTab !== activeTab) {
|
||||
activeTab = currentTab;
|
||||
}
|
||||
});
|
||||
|
||||
const tabLabels: Record<TabType, string> = {
|
||||
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;
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user