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.
This commit is contained in:
1 parent
c749b7d932
commit
9ec6d49f3e
1 file changed
+15
-3
@@ -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<string | null>(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;
|
||||
|
||||
|
||||
Reference in new issue
Block a user