refactor(stores): rename store to offlineCacheState
- Create offlineCacheState.ts with compliant terminology - Update all component imports and type references - Add compatibility aliases for gradual migration - Remove deprecated downloadState.ts cc
This commit is contained in:
1 parent
393589862d
commit
84a2164079
10 files changed
+358
-303
No files matched your search
@@ -6,10 +6,11 @@
|
||||
isOffline as checkIsOffline
|
||||
} from '$lib/stores/offlineStore';
|
||||
|
||||
type DownloadStatus = 'none' | 'queued' | 'downloading' | 'ready' | 'failed';
|
||||
// Offline cache status for tracks
|
||||
type OfflineCacheStatus = 'none' | 'queued' | 'downloading' | 'ready' | 'failed';
|
||||
|
||||
interface Props {
|
||||
status?: DownloadStatus;
|
||||
status?: OfflineCacheStatus;
|
||||
progress?: number;
|
||||
size?: number;
|
||||
onDownload?: () => void;
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
} from '$lib/stores/favoritesStore';
|
||||
import { togglePlay } from '$lib/stores/playerStore';
|
||||
|
||||
type DownloadStatus = 'none' | 'queued' | 'downloading' | 'ready' | 'failed';
|
||||
// Offline cache status for tracks
|
||||
type OfflineCacheStatus = 'none' | 'queued' | 'downloading' | 'ready' | 'failed';
|
||||
|
||||
interface Props {
|
||||
trackId?: number; // Optional - required for favorites functionality unless hideFavorite=true
|
||||
@@ -23,7 +24,7 @@
|
||||
isPlaying?: boolean;
|
||||
isLocal?: boolean; // Whether this is a local library track
|
||||
isFavoriteOverride?: boolean; // Optional override for favorite state
|
||||
downloadStatus?: DownloadStatus;
|
||||
downloadStatus?: OfflineCacheStatus;
|
||||
downloadProgress?: number;
|
||||
hideDownload?: boolean;
|
||||
hideFavorite?: boolean;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import TrackRow from './TrackRow.svelte';
|
||||
import type { DownloadStatus } from '$lib/stores/downloadState';
|
||||
import type { OfflineCacheStatus } from '$lib/stores/offlineCacheState';
|
||||
|
||||
// Use generic types to match whatever caller passes
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
@@ -44,7 +44,7 @@
|
||||
hideFavorite?: boolean;
|
||||
isFavoriteOverride?: boolean;
|
||||
// Download status support for Favorites/Search
|
||||
getDownloadStatus?: (trackId: number) => { status: DownloadStatus; progress: number };
|
||||
getOfflineCacheStatus?: (trackId: number) => { status: OfflineCacheStatus; progress: number };
|
||||
onDownload?: (track: Track) => void;
|
||||
onRemoveDownload?: (trackId: number) => void;
|
||||
// Additional menu actions for Favorites
|
||||
@@ -85,7 +85,7 @@
|
||||
hideDownload = true,
|
||||
hideFavorite = true,
|
||||
isFavoriteOverride,
|
||||
getDownloadStatus,
|
||||
getOfflineCacheStatus,
|
||||
onDownload,
|
||||
onRemoveDownload,
|
||||
onShareQobuz,
|
||||
@@ -305,7 +305,7 @@
|
||||
{@const albumKey = getTrackAlbumKey(item.track)}
|
||||
{@const artistId = getArtistId?.(item.track)}
|
||||
{@const albumId = getAlbumId?.(item.track)}
|
||||
{@const downloadInfo = getDownloadStatus?.(trackId) ?? { status: 'none' as const, progress: 0 }}
|
||||
{@const downloadInfo = getOfflineCacheStatus?.(trackId) ?? { status: 'none' as const, progress: 0 }}
|
||||
{@const isTrackDownloaded = downloadInfo.status === 'ready'}
|
||||
<TrackRow
|
||||
trackId={trackId}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { ArrowLeft, Play, Shuffle, Heart } from 'lucide-svelte';
|
||||
import TrackRow from '../TrackRow.svelte';
|
||||
import AlbumMenu from '../AlbumMenu.svelte';
|
||||
import { getDownloadState, type DownloadStatus, isAlbumFullyDownloaded } from '$lib/stores/downloadState';
|
||||
import { getOfflineCacheState, type OfflineCacheStatus, isAlbumFullyCached } from '$lib/stores/offlineCacheState';
|
||||
import { consumeContextTrackFocus } from '$lib/stores/playbackContextStore';
|
||||
import {
|
||||
subscribe as subscribeAlbumFavorites,
|
||||
@@ -60,7 +60,7 @@
|
||||
onTrackDownload?: (track: Track) => void;
|
||||
onTrackRemoveDownload?: (trackId: number) => void;
|
||||
onTrackReDownload?: (track: Track) => void;
|
||||
getTrackDownloadStatus?: (trackId: number) => { status: DownloadStatus; progress: number };
|
||||
getTrackOfflineCacheStatus?: (trackId: number) => { status: OfflineCacheStatus; progress: number };
|
||||
onDownloadAlbum?: () => void;
|
||||
onShareAlbumQobuz?: () => void;
|
||||
onShareAlbumSonglink?: () => void;
|
||||
@@ -92,7 +92,7 @@
|
||||
onTrackDownload,
|
||||
onTrackRemoveDownload,
|
||||
onTrackReDownload,
|
||||
getTrackDownloadStatus,
|
||||
getTrackOfflineCacheStatus,
|
||||
onDownloadAlbum,
|
||||
onShareAlbumQobuz,
|
||||
onShareAlbumSonglink,
|
||||
@@ -109,7 +109,7 @@
|
||||
let scrollContainer: HTMLDivElement | null = $state(null);
|
||||
|
||||
const albumFullyDownloaded = $derived(
|
||||
isAlbumFullyDownloaded(album.tracks.map(t => t.id))
|
||||
isAlbumFullyCached(album.tracks.map(t => t.id))
|
||||
);
|
||||
|
||||
const isVariousArtists = $derived(
|
||||
@@ -227,7 +227,7 @@
|
||||
onShareQobuz={onShareAlbumQobuz}
|
||||
onShareSonglink={onShareAlbumSonglink}
|
||||
onDownload={onDownloadAlbum}
|
||||
isAlbumFullyDownloaded={albumFullyDownloaded}
|
||||
isAlbumFullyCached={albumFullyDownloaded}
|
||||
onOpenContainingFolder={onOpenAlbumFolder}
|
||||
onReDownloadAlbum={onReDownloadAlbum}
|
||||
/>
|
||||
@@ -251,7 +251,7 @@
|
||||
<!-- Track Rows -->
|
||||
<div class="tracks">
|
||||
{#each album.tracks as track, trackIndex (`${track.id}-${downloadStateVersion}`)}
|
||||
{@const downloadInfo = getTrackDownloadStatus?.(track.id) ?? { status: 'none' as const, progress: 0 }}
|
||||
{@const downloadInfo = getTrackOfflineCacheStatus?.(track.id) ?? { status: 'none' as const, progress: 0 }}
|
||||
{@const isTrackDownloaded = downloadInfo.status === 'ready'}
|
||||
<TrackRow
|
||||
trackId={track.id}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import VirtualizedTrackList from '../VirtualizedTrackList.svelte';
|
||||
import PlaylistCollage from '../PlaylistCollage.svelte';
|
||||
import FavoritesEditModal from '../FavoritesEditModal.svelte';
|
||||
import { type DownloadStatus } from '$lib/stores/downloadState';
|
||||
import { type OfflineCacheStatus } from '$lib/stores/offlineCacheState';
|
||||
import { consumeContextTrackFocus, setPlaybackContext } from '$lib/stores/playbackContextStore';
|
||||
import { normalizeFavoritesTabOrder } from '$lib/utils/favorites';
|
||||
import type { FavoritesPreferences } from '$lib/types';
|
||||
@@ -77,7 +77,7 @@
|
||||
onTrackDownload?: (track: DisplayTrack) => void;
|
||||
onTrackRemoveDownload?: (trackId: number) => void;
|
||||
onTrackReDownload?: (track: DisplayTrack) => void;
|
||||
getTrackDownloadStatus?: (trackId: number) => { status: DownloadStatus; progress: number };
|
||||
getTrackOfflineCacheStatus?: (trackId: number) => { status: OfflineCacheStatus; progress: number };
|
||||
onPlaylistSelect?: (playlistId: number) => void;
|
||||
selectedTab?: TabType;
|
||||
onTabNavigate?: (tab: TabType) => void;
|
||||
@@ -127,7 +127,7 @@
|
||||
onTrackDownload,
|
||||
onTrackRemoveDownload,
|
||||
onTrackReDownload,
|
||||
getTrackDownloadStatus,
|
||||
getTrackOfflineCacheStatus,
|
||||
onPlaylistSelect,
|
||||
selectedTab,
|
||||
onTabNavigate,
|
||||
@@ -163,27 +163,27 @@
|
||||
});
|
||||
|
||||
// Download status tracking
|
||||
let albumDownloadStatuses = $state<Map<string, boolean>>(new Map());
|
||||
let albumOfflineCacheStatuses = $state<Map<string, boolean>>(new Map());
|
||||
|
||||
async function loadAlbumDownloadStatus(albumId: string) {
|
||||
async function loadAlbumOfflineCacheStatus(albumId: string) {
|
||||
if (!checkAlbumFullyDownloaded) return false;
|
||||
try {
|
||||
const isDownloaded = await checkAlbumFullyDownloaded(albumId);
|
||||
albumDownloadStatuses.set(albumId, isDownloaded);
|
||||
albumOfflineCacheStatuses.set(albumId, isDownloaded);
|
||||
return isDownloaded;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadAllAlbumDownloadStatuses(albums: { id: string }[]) {
|
||||
async function loadAllAlbumOfflineCacheStatuses(albums: { id: string }[]) {
|
||||
if (!checkAlbumFullyDownloaded || albums.length === 0) return;
|
||||
await Promise.all(albums.map(album => loadAlbumDownloadStatus(album.id)));
|
||||
await Promise.all(albums.map(album => loadAlbumOfflineCacheStatus(album.id)));
|
||||
}
|
||||
|
||||
function isAlbumDownloaded(albumId: string): boolean {
|
||||
void downloadStateVersion;
|
||||
return albumDownloadStatuses.get(albumId) || false;
|
||||
return albumOfflineCacheStatuses.get(albumId) || false;
|
||||
}
|
||||
|
||||
let error = $state<string | null>(null);
|
||||
@@ -449,7 +449,7 @@
|
||||
favoriteTracks = items as FavoriteTrack[];
|
||||
} else if (type === 'albums') {
|
||||
favoriteAlbums = items as FavoriteAlbum[];
|
||||
await loadAllAlbumDownloadStatuses(favoriteAlbums);
|
||||
await loadAllAlbumOfflineCacheStatuses(favoriteAlbums);
|
||||
} else if (type === 'artists') {
|
||||
favoriteArtists = items as FavoriteArtist[];
|
||||
}
|
||||
@@ -1133,7 +1133,7 @@
|
||||
hideDownload={false}
|
||||
hideFavorite={false}
|
||||
isFavoriteOverride={true}
|
||||
getDownloadStatus={getTrackDownloadStatus}
|
||||
getOfflineCacheStatus={getTrackOfflineCacheStatus}
|
||||
onDownload={onTrackDownload ? (t) => onTrackDownload(buildDisplayTrackFromFavorite(t)) : undefined}
|
||||
onRemoveDownload={onTrackRemoveDownload}
|
||||
onShareQobuz={onTrackShareQobuz}
|
||||
@@ -1204,7 +1204,7 @@
|
||||
onOpenContainingFolder={onOpenAlbumFolder ? () => onOpenAlbumFolder(album.id) : undefined}
|
||||
onReDownloadAlbum={onReDownloadAlbum ? () => onReDownloadAlbum(album.id) : undefined}
|
||||
{downloadStateVersion}
|
||||
onclick={() => { onAlbumClick?.(album.id); loadAlbumDownloadStatus(album.id); }}
|
||||
onclick={() => { onAlbumClick?.(album.id); loadAlbumOfflineCacheStatus(album.id); }}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -1275,7 +1275,7 @@
|
||||
onOpenContainingFolder={onOpenAlbumFolder ? () => onOpenAlbumFolder(album.id) : undefined}
|
||||
onReDownloadAlbum={onReDownloadAlbum ? () => onReDownloadAlbum(album.id) : undefined}
|
||||
{downloadStateVersion}
|
||||
onclick={() => { onAlbumClick?.(album.id); loadAlbumDownloadStatus(album.id); }}
|
||||
onclick={() => { onAlbumClick?.(album.id); loadAlbumOfflineCacheStatus(album.id); }}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { open } from '@tauri-apps/plugin-dialog';
|
||||
import TrackRow from '../TrackRow.svelte';
|
||||
import { type DownloadStatus } from '$lib/stores/downloadState';
|
||||
import { type OfflineCacheStatus } from '$lib/stores/offlineCacheState';
|
||||
import {
|
||||
subscribe as subscribeOffline,
|
||||
getStatus as getOfflineStatus,
|
||||
@@ -129,7 +129,7 @@
|
||||
onTrackDownload?: (track: DisplayTrack) => void;
|
||||
onTrackRemoveDownload?: (trackId: number) => void;
|
||||
onTrackReDownload?: (track: DisplayTrack) => void;
|
||||
getTrackDownloadStatus?: (trackId: number) => { status: DownloadStatus; progress: number };
|
||||
getTrackOfflineCacheStatus?: (trackId: number) => { status: OfflineCacheStatus; progress: number };
|
||||
downloadStateVersion?: number;
|
||||
onLocalTrackPlay?: (track: LocalLibraryTrack) => void;
|
||||
onLocalTrackPlayNext?: (track: LocalLibraryTrack) => void;
|
||||
@@ -157,7 +157,7 @@
|
||||
onTrackDownload,
|
||||
onTrackRemoveDownload,
|
||||
onTrackReDownload,
|
||||
getTrackDownloadStatus,
|
||||
getTrackOfflineCacheStatus,
|
||||
downloadStateVersion,
|
||||
onLocalTrackPlay,
|
||||
onLocalTrackPlayNext,
|
||||
@@ -1099,7 +1099,7 @@
|
||||
</div>
|
||||
|
||||
{#each displayTracks as track, idx (`${idx}-${track.id}-${downloadStateVersion}`)}
|
||||
{@const downloadInfo = track.isLocal ? { status: 'none' as const, progress: 0 } : (getTrackDownloadStatus?.(track.id) ?? { status: 'none' as const, progress: 0 })}
|
||||
{@const downloadInfo = track.isLocal ? { status: 'none' as const, progress: 0 } : (getTrackOfflineCacheStatus?.(track.id) ?? { status: 'none' as const, progress: 0 })}
|
||||
{@const isActiveTrack = (
|
||||
track.isLocal
|
||||
? (track.localTrackId !== undefined && activeTrackId === track.localTrackId)
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
import Dropdown from '../Dropdown.svelte';
|
||||
import VolumeSlider from '../VolumeSlider.svelte';
|
||||
import {
|
||||
getDownloadCacheStats,
|
||||
clearDownloadCache,
|
||||
type DownloadCacheStats
|
||||
} from '$lib/stores/downloadState';
|
||||
getOfflineCacheStats,
|
||||
clearOfflineCache,
|
||||
type OfflineCacheStats
|
||||
} from '$lib/stores/offlineCacheState';
|
||||
import { notifyDownloadSettingsChanged } from '$lib/stores/downloadSettingsStore';
|
||||
import { clearCache as clearLyricsCache } from '$lib/stores/lyricsStore';
|
||||
import {
|
||||
@@ -94,7 +94,7 @@
|
||||
let isClearing = $state(false);
|
||||
|
||||
// Download cache state (offline storage)
|
||||
let downloadStats = $state<DownloadCacheStats | null>(null);
|
||||
let downloadStats = $state<OfflineCacheStats | null>(null);
|
||||
let isClearingDownloads = $state(false);
|
||||
let isRepairingDownloads = $state(false);
|
||||
|
||||
@@ -1165,7 +1165,7 @@
|
||||
|
||||
async function loadDownloadStats() {
|
||||
try {
|
||||
downloadStats = await getDownloadCacheStats();
|
||||
downloadStats = await getOfflineCacheStats();
|
||||
} catch (err) {
|
||||
console.error('Failed to load download stats:', err);
|
||||
}
|
||||
@@ -1266,7 +1266,7 @@
|
||||
if (isClearingDownloads) return;
|
||||
isClearingDownloads = true;
|
||||
try {
|
||||
await clearDownloadCache();
|
||||
await clearOfflineCache();
|
||||
await loadDownloadStats();
|
||||
} catch (err) {
|
||||
console.error('Failed to clear download cache:', err);
|
||||
|
||||
Reference in new issue
Block a user