refactor: simplify initial state fetching in MusicPlayerProvider

This commit is contained in:
JSC
2025-07-07 21:34:23 +02:00
parent b8bac2b6a9
commit 328768db58

View File

@@ -91,19 +91,7 @@ export function MusicPlayerProvider({ children }: MusicPlayerProviderProps) {
const fetchInitialState = async () => { const fetchInitialState = async () => {
try { try {
const response = await apiService.get('/api/player/state') const response = await apiService.get('/api/player/state')
let state = await response.json() const state = await response.json()
// If no playlist is loaded, try to load the main playlist
if (!state.playlist_id) {
try {
await apiService.post('/api/player/load-main-playlist')
// Fetch state again after loading main playlist
const newResponse = await apiService.get('/api/player/state')
state = await newResponse.json()
} catch (loadError) {
console.warn('Failed to load main playlist:', loadError)
}
}
// Update all state from backend // Update all state from backend
setIsPlaying(state.is_playing || false) setIsPlaying(state.is_playing || false)