From 9ec6d49f3e4af5dd17c64d88490be30fafaab76b Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Tue, 20 Jan 2026 14:44:29 -0600 Subject: [PATCH] Fix PlaylistModal not detecting offline state reactively Problem: When creating a playlist in offline mode, the modal would create it in Qobuz instead of as a pending playlist because it read the offline state only once at modal open time. Solution: Subscribe to offline state changes reactively using $effect and update a reactive offlineMode variable that the modal uses instead of calling isOffline() directly. This ensures the modal always has the current offline state, even if the user toggles offline mode while the modal is open. --- src/lib/components/PlaylistModal.svelte | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/lib/components/PlaylistModal.svelte b/src/lib/components/PlaylistModal.svelte index fae1b78a3..fa6ab27c7 100644 --- a/src/lib/components/PlaylistModal.svelte +++ b/src/lib/components/PlaylistModal.svelte @@ -2,7 +2,7 @@ import { invoke } from '@tauri-apps/api/core'; import { X, Trash2, EyeOff, Eye } from 'lucide-svelte'; import { logPlaylistAdd } from '$lib/services/recoService'; - import { isOffline, createPendingPlaylist } from '$lib/stores/offlineStore'; + import { subscribe as subscribeOffline, getStatus, createPendingPlaylist } from '$lib/stores/offlineStore'; import { showToast } from '$lib/stores/toastStore'; interface Playlist { @@ -46,6 +46,9 @@ let loading = $state(false); let error = $state(null); + // Offline state (reactive) + let offlineMode = $state(false); + // Special value for "create new playlist" option (won't collide with negative pending playlist IDs) const CREATE_NEW_PLAYLIST = -999999; @@ -73,6 +76,15 @@ return pl.tracks_count + localCount; } + // Subscribe to offline state changes + $effect(() => { + const unsubscribe = subscribeOffline(() => { + const status = getStatus(); + offlineMode = status.isOffline; + }); + return unsubscribe; + }); + // Reset form when modal opens $effect(() => { if (isOpen) { @@ -106,7 +118,7 @@ error = null; try { - if (isOffline()) { + if (offlineMode) { // Create pending playlist for sync when back online const pendingId = await createPendingPlaylist( name.trim(), @@ -270,7 +282,7 @@ error = null; try { - if (isOffline()) { + if (offlineMode) { // In offline mode, create pending playlist with both Qobuz and local tracks const qobuzTrackIds = isLocalTracks ? [] : trackIds;