feat(offline): add view access restrictions for offline mode

- Create OfflinePlaceholder component with reason-specific messaging
- Add i18n strings for offline mode (en/es)
- Subscribe to offlineStore in +page.svelte
- Show OfflinePlaceholder for home, search, favorites views when offline
- Provide quick navigation to local library from placeholder

cc
This commit is contained in:
vicrodh committed 2026-01-15 22:19:17 -06:00
1 parent 1b9fff3746
commit b7c1af6123
4 files changed
+272 -65

No files matched your search

@@ -0,0 +1,119 @@
<script lang="ts">
import { WifiOff, CloudOff, Power, Library } from 'lucide-svelte';
import { t } from '$lib/i18n';
import type { OfflineReason } from '$lib/stores/offlineStore';
interface Props {
reason?: OfflineReason | null;
onGoToLibrary?: () => void;
}
let { reason = null, onGoToLibrary }: Props = $props();
// Get icon based on reason
function getIcon(r: OfflineReason | null) {
switch (r) {
case 'no_network': return WifiOff;
case 'not_logged_in': return CloudOff;
case 'manual_override': return Power;
default: return WifiOff;
}
}
const icon = $derived(getIcon(reason));
</script>
<div class="offline-placeholder">
<div class="content">
<div class="icon-container">
<svelte:component this={icon} size={64} strokeWidth={1.5} />
</div>
<h2>
{#if reason === 'no_network'}
{$t('offline.noNetwork')}
{:else if reason === 'not_logged_in'}
{$t('offline.notLoggedIn')}
{:else if reason === 'manual_override'}
{$t('offline.manualMode')}
{:else}
{$t('offline.title')}
{/if}
</h2>
<p>
{#if reason === 'no_network'}
{$t('offline.noNetworkMessage')}
{:else if reason === 'not_logged_in'}
{$t('offline.notLoggedInMessage')}
{:else if reason === 'manual_override'}
{$t('offline.manualModeMessage')}
{:else}
{$t('offline.message')}
{/if}
</p>
{#if onGoToLibrary}
<button class="library-button" onclick={onGoToLibrary}>
<Library size={18} />
<span>{$t('offline.goToLibrary')}</span>
</button>
{/if}
</div>
</div>
<style>
.offline-placeholder {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
min-height: 400px;
padding: 48px;
}
.content {
text-align: center;
max-width: 400px;
}
.icon-container {
color: var(--color-text-tertiary);
margin-bottom: 24px;
opacity: 0.6;
}
h2 {
font-size: 1.5rem;
font-weight: 600;
color: var(--color-text-primary);
margin: 0 0 12px 0;
}
p {
font-size: 0.95rem;
color: var(--color-text-secondary);
margin: 0 0 24px 0;
line-height: 1.5;
}
.library-button {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 12px 24px;
background: var(--color-primary);
color: var(--color-on-primary);
border: none;
border-radius: 8px;
font-size: 0.95rem;
font-weight: 500;
cursor: pointer;
transition: background 0.2s, transform 0.1s;
}
.library-button:hover {
background: var(--color-primary-hover);
}
.library-button:active {
transform: scale(0.98);
}
</style>
+24
View File
@@ -420,5 +420,29 @@
"moveUp": "Move up",
"moveDown": "Move down",
"resetToDefaults": "Reset to defaults"
},
"offline": {
"title": "Offline Mode",
"message": "Connect to the internet to access Qobuz content.",
"noNetwork": "No Network Connection",
"noNetworkMessage": "Check your internet connection to access Qobuz streaming.",
"notLoggedIn": "Not Logged In",
"notLoggedInMessage": "Log in to your Qobuz account to access streaming content.",
"manualMode": "Offline Mode Enabled",
"manualModeMessage": "You have manually enabled offline mode. Your local library is still available.",
"goToLibrary": "Go to Local Library",
"enableManual": "Enable Offline Mode",
"enableManualDesc": "Manually switch to offline mode even with internet",
"showPartialPlaylists": "Show Partial Playlists",
"showPartialPlaylistsDesc": "Show playlists with some local content in offline mode",
"status": "Status",
"online": "Online",
"offlineReason": "Offline",
"indicator": "Offline",
"allLocal": "Fully Available Offline",
"someLocal": "Partially Available Offline",
"notAvailable": "Not Available Offline",
"trackNotAvailable": "This track is not available offline",
"featureDisabled": "This feature requires internet connection"
}
}
+24
View File
@@ -420,5 +420,29 @@
"moveUp": "Subir",
"moveDown": "Bajar",
"resetToDefaults": "Restablecer valores"
},
"offline": {
"title": "Modo Offline",
"message": "Conecta a internet para acceder al contenido de Qobuz.",
"noNetwork": "Sin Conexion a Internet",
"noNetworkMessage": "Verifica tu conexion para acceder al streaming de Qobuz.",
"notLoggedIn": "No Has Iniciado Sesion",
"notLoggedInMessage": "Inicia sesion en tu cuenta de Qobuz para acceder al contenido.",
"manualMode": "Modo Offline Activado",
"manualModeMessage": "Has activado el modo offline manualmente. Tu biblioteca local sigue disponible.",
"goToLibrary": "Ir a Biblioteca Local",
"enableManual": "Activar Modo Offline",
"enableManualDesc": "Cambiar manualmente a modo offline incluso con internet",
"showPartialPlaylists": "Mostrar Listas Parciales",
"showPartialPlaylistsDesc": "Mostrar listas con algo de contenido local en modo offline",
"status": "Estado",
"online": "En linea",
"offlineReason": "Offline",
"indicator": "Offline",
"allLocal": "Disponible Offline",
"someLocal": "Parcialmente Disponible Offline",
"notAvailable": "No Disponible Offline",
"trackNotAvailable": "Esta pista no esta disponible offline",
"featureDisabled": "Esta funcion requiere conexion a internet"
}
}
+105 -65
View File
@@ -247,11 +247,24 @@
import PlaylistImportModal from '$lib/components/PlaylistImportModal.svelte';
import CastPicker from '$lib/components/CastPicker.svelte';
import LyricsSidebar from '$lib/components/lyrics/LyricsSidebar.svelte';
import OfflinePlaceholder from '$lib/components/OfflinePlaceholder.svelte';
// Offline state
import {
subscribe as subscribeOffline,
getStatus as getOfflineStatus,
isOffline as checkIsOffline,
getOfflineReason,
type OfflineStatus
} from '$lib/stores/offlineStore';
// Auth State (from authStore subscription)
let isLoggedIn = $state(false);
let userInfo = $state<UserInfo | null>(null);
// Offline State (from offlineStore subscription)
let offlineStatus = $state<OfflineStatus>(getOfflineStatus());
// View State (from navigationStore subscription)
let activeView = $state<ViewType>('home');
let selectedPlaylistId = $state<number | null>(null);
@@ -1527,6 +1540,11 @@
userInfo = authState.userInfo;
});
// Subscribe to offline state changes
const unsubscribeOffline = subscribeOffline(() => {
offlineStatus = getOfflineStatus();
});
// Subscribe to navigation state changes
const unsubscribeNav = subscribeNav(() => {
const navState = getNavigationState();
@@ -1708,6 +1726,7 @@
unsubscribeToast();
unsubscribeUI();
unsubscribeAuth();
unsubscribeOffline();
unsubscribeNav();
unsubscribePlayer();
unsubscribeQueue();
@@ -1781,46 +1800,60 @@
<!-- Main Content -->
<main class="main-content">
{#if activeView === 'home'}
<HomeView
userName={userInfo?.userName}
onAlbumClick={handleAlbumClick}
onAlbumPlay={playAlbumById}
onAlbumPlayNext={queueAlbumNextById}
onAlbumPlayLater={queueAlbumLaterById}
onAlbumShareQobuz={shareAlbumQobuzLinkById}
onAlbumShareSonglink={shareAlbumSonglinkById}
onAlbumDownload={downloadAlbumById}
onOpenAlbumFolder={openAlbumFolderById}
onReDownloadAlbum={reDownloadAlbumById}
checkAlbumFullyDownloaded={checkAlbumFullyDownloaded}
{downloadStateVersion}
onArtistClick={handleArtistClick}
onTrackPlay={handleDisplayTrackPlay}
/>
{#if offlineStatus.isOffline}
<OfflinePlaceholder
reason={offlineStatus.reason}
onGoToLibrary={() => navigateTo('library')}
/>
{:else}
<HomeView
userName={userInfo?.userName}
onAlbumClick={handleAlbumClick}
onAlbumPlay={playAlbumById}
onAlbumPlayNext={queueAlbumNextById}
onAlbumPlayLater={queueAlbumLaterById}
onAlbumShareQobuz={shareAlbumQobuzLinkById}
onAlbumShareSonglink={shareAlbumSonglinkById}
onAlbumDownload={downloadAlbumById}
onOpenAlbumFolder={openAlbumFolderById}
onReDownloadAlbum={reDownloadAlbumById}
checkAlbumFullyDownloaded={checkAlbumFullyDownloaded}
{downloadStateVersion}
onArtistClick={handleArtistClick}
onTrackPlay={handleDisplayTrackPlay}
/>
{/if}
{:else if activeView === 'search'}
<SearchView
onAlbumClick={handleAlbumClick}
onAlbumPlay={playAlbumById}
onAlbumPlayNext={queueAlbumNextById}
onAlbumPlayLater={queueAlbumLaterById}
onAlbumShareQobuz={shareAlbumQobuzLinkById}
onAlbumShareSonglink={shareAlbumSonglinkById}
onAlbumDownload={downloadAlbumById}
onOpenAlbumFolder={openAlbumFolderById}
onReDownloadAlbum={reDownloadAlbumById}
checkAlbumFullyDownloaded={checkAlbumFullyDownloaded}
{downloadStateVersion}
onTrackPlay={handleTrackPlay}
onTrackPlayNext={queueQobuzTrackNext}
onTrackPlayLater={queueQobuzTrackLater}
onTrackAddFavorite={handleAddToFavorites}
onTrackAddToPlaylist={(trackId) => openAddToPlaylist([trackId])}
onTrackShareQobuz={shareQobuzTrackLink}
onTrackShareSonglink={(track) => shareSonglinkTrack(track.id, track.isrc)}
onTrackGoToAlbum={handleAlbumClick}
onTrackGoToArtist={handleArtistClick}
onArtistClick={handleArtistClick}
/>
{#if offlineStatus.isOffline}
<OfflinePlaceholder
reason={offlineStatus.reason}
onGoToLibrary={() => navigateTo('library')}
/>
{:else}
<SearchView
onAlbumClick={handleAlbumClick}
onAlbumPlay={playAlbumById}
onAlbumPlayNext={queueAlbumNextById}
onAlbumPlayLater={queueAlbumLaterById}
onAlbumShareQobuz={shareAlbumQobuzLinkById}
onAlbumShareSonglink={shareAlbumSonglinkById}
onAlbumDownload={downloadAlbumById}
onOpenAlbumFolder={openAlbumFolderById}
onReDownloadAlbum={reDownloadAlbumById}
checkAlbumFullyDownloaded={checkAlbumFullyDownloaded}
{downloadStateVersion}
onTrackPlay={handleTrackPlay}
onTrackPlayNext={queueQobuzTrackNext}
onTrackPlayLater={queueQobuzTrackLater}
onTrackAddFavorite={handleAddToFavorites}
onTrackAddToPlaylist={(trackId) => openAddToPlaylist([trackId])}
onTrackShareQobuz={shareQobuzTrackLink}
onTrackShareSonglink={(track) => shareSonglinkTrack(track.id, track.isrc)}
onTrackGoToAlbum={handleAlbumClick}
onTrackGoToArtist={handleArtistClick}
onArtistClick={handleArtistClick}
/>
{/if}
{:else if activeView === 'settings'}
<SettingsView
onBack={navGoBack}
@@ -1921,32 +1954,39 @@
onPlaylistDeleted={() => { sidebarRef?.refreshPlaylists(); navGoBack(); }}
/>
{:else if activeView === 'favorites'}
<FavoritesView
onAlbumClick={handleAlbumClick}
onAlbumPlay={playAlbumById}
onAlbumPlayNext={queueAlbumNextById}
onAlbumPlayLater={queueAlbumLaterById}
onAlbumShareQobuz={shareAlbumQobuzLinkById}
onAlbumShareSonglink={shareAlbumSonglinkById}
onAlbumDownload={downloadAlbumById}
onOpenAlbumFolder={openAlbumFolderById}
onReDownloadAlbum={reDownloadAlbumById}
checkAlbumFullyDownloaded={checkAlbumFullyDownloaded}
{downloadStateVersion}
onTrackPlay={handleDisplayTrackPlay}
onArtistClick={handleArtistClick}
onTrackPlayNext={queuePlaylistTrackNext}
onTrackPlayLater={queuePlaylistTrackLater}
onTrackAddFavorite={handleAddToFavorites}
onTrackAddToPlaylist={(trackId) => openAddToPlaylist([trackId])}
onTrackShareQobuz={shareQobuzTrackLink}
onTrackShareSonglink={(track) => shareSonglinkTrack(track.id, track.isrc)}
onTrackGoToAlbum={handleAlbumClick}
onTrackGoToArtist={handleArtistClick}
onTrackDownload={handleDisplayTrackDownload}
onTrackRemoveDownload={handleTrackRemoveDownload}
getTrackDownloadStatus={getTrackDownloadStatus}
/>
{#if offlineStatus.isOffline}
<OfflinePlaceholder
reason={offlineStatus.reason}
onGoToLibrary={() => navigateTo('library')}
/>
{:else}
<FavoritesView
onAlbumClick={handleAlbumClick}
onAlbumPlay={playAlbumById}
onAlbumPlayNext={queueAlbumNextById}
onAlbumPlayLater={queueAlbumLaterById}
onAlbumShareQobuz={shareAlbumQobuzLinkById}
onAlbumShareSonglink={shareAlbumSonglinkById}
onAlbumDownload={downloadAlbumById}
onOpenAlbumFolder={openAlbumFolderById}
onReDownloadAlbum={reDownloadAlbumById}
checkAlbumFullyDownloaded={checkAlbumFullyDownloaded}
{downloadStateVersion}
onTrackPlay={handleDisplayTrackPlay}
onArtistClick={handleArtistClick}
onTrackPlayNext={queuePlaylistTrackNext}
onTrackPlayLater={queuePlaylistTrackLater}
onTrackAddFavorite={handleAddToFavorites}
onTrackAddToPlaylist={(trackId) => openAddToPlaylist([trackId])}
onTrackShareQobuz={shareQobuzTrackLink}
onTrackShareSonglink={(track) => shareSonglinkTrack(track.id, track.isrc)}
onTrackGoToAlbum={handleAlbumClick}
onTrackGoToArtist={handleArtistClick}
onTrackDownload={handleDisplayTrackDownload}
onTrackRemoveDownload={handleTrackRemoveDownload}
getTrackDownloadStatus={getTrackDownloadStatus}
/>
{/if}
{:else if activeView === 'playlist-manager'}
<PlaylistManagerView
onBack={navGoBack}