Create pending playlists when offline instead of calling API
- Detect offline mode in handleCreate and handleCreateAndAdd - Use createPendingPlaylist() to queue playlist creation for sync - Show toast notification that playlist will sync when back online - Prevent creating playlists with local tracks in offline mode - Fixes network error when trying to create playlist while offline
This commit is contained in:
1 parent
5cd18b425a
commit
58515cc3f4
1 file changed
+58
-8
@@ -2,6 +2,8 @@
|
|||||||
import { invoke } from '@tauri-apps/api/core';
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
import { X, Trash2, EyeOff, Eye } from 'lucide-svelte';
|
import { X, Trash2, EyeOff, Eye } from 'lucide-svelte';
|
||||||
import { logPlaylistAdd } from '$lib/services/recoService';
|
import { logPlaylistAdd } from '$lib/services/recoService';
|
||||||
|
import { isOffline, createPendingPlaylist } from '$lib/stores/offlineStore';
|
||||||
|
import { showToast } from '$lib/stores/toastStore';
|
||||||
|
|
||||||
interface Playlist {
|
interface Playlist {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -101,13 +103,33 @@
|
|||||||
error = null;
|
error = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const newPlaylist = await invoke<Playlist>('create_playlist', {
|
if (isOffline()) {
|
||||||
name: name.trim(),
|
// Create pending playlist for sync when back online
|
||||||
description: description.trim() || null,
|
const pendingId = await createPendingPlaylist(
|
||||||
isPublic
|
name.trim(),
|
||||||
});
|
description.trim() || null,
|
||||||
onSuccess?.(newPlaylist);
|
isPublic,
|
||||||
onClose();
|
[]
|
||||||
|
);
|
||||||
|
showToast('Playlist created offline - will sync when back online', 'info');
|
||||||
|
// Create a temporary playlist object for UI
|
||||||
|
const tempPlaylist: Playlist = {
|
||||||
|
id: -pendingId, // Negative ID to distinguish from real playlists
|
||||||
|
name: name.trim(),
|
||||||
|
tracks_count: 0
|
||||||
|
};
|
||||||
|
onSuccess?.(tempPlaylist);
|
||||||
|
onClose();
|
||||||
|
} else {
|
||||||
|
// Create playlist normally via API
|
||||||
|
const newPlaylist = await invoke<Playlist>('create_playlist', {
|
||||||
|
name: name.trim(),
|
||||||
|
description: description.trim() || null,
|
||||||
|
isPublic
|
||||||
|
});
|
||||||
|
onSuccess?.(newPlaylist);
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to create playlist:', err);
|
console.error('Failed to create playlist:', err);
|
||||||
error = String(err);
|
error = String(err);
|
||||||
@@ -222,7 +244,35 @@
|
|||||||
error = null;
|
error = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Create the playlist first
|
if (isOffline()) {
|
||||||
|
// In offline mode, can only create pending playlists with Qobuz tracks
|
||||||
|
if (isLocalTracks) {
|
||||||
|
error = 'Cannot create playlist with local tracks in offline mode';
|
||||||
|
loading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create pending playlist with Qobuz tracks for sync when back online
|
||||||
|
const pendingId = await createPendingPlaylist(
|
||||||
|
name.trim(),
|
||||||
|
description.trim() || null,
|
||||||
|
false,
|
||||||
|
trackIds
|
||||||
|
);
|
||||||
|
showToast(`Playlist "${name.trim()}" created offline - will sync when back online`, 'info');
|
||||||
|
|
||||||
|
// Create a temporary playlist object for UI
|
||||||
|
const tempPlaylist: Playlist = {
|
||||||
|
id: -pendingId, // Negative ID to distinguish from real playlists
|
||||||
|
name: name.trim(),
|
||||||
|
tracks_count: trackIds.length
|
||||||
|
};
|
||||||
|
onSuccess?.(tempPlaylist);
|
||||||
|
onClose();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Online mode - create the playlist first
|
||||||
const newPlaylist = await invoke<Playlist>('create_playlist', {
|
const newPlaylist = await invoke<Playlist>('create_playlist', {
|
||||||
name: name.trim(),
|
name: name.trim(),
|
||||||
description: description.trim() || null,
|
description: description.trim() || null,
|
||||||
|
|||||||
Reference in new issue
Block a user