refactor: simplify initial state fetching in MusicPlayerProvider
This commit is contained in:
@@ -91,19 +91,7 @@ export function MusicPlayerProvider({ children }: MusicPlayerProviderProps) {
|
||||
const fetchInitialState = async () => {
|
||||
try {
|
||||
const response = await apiService.get('/api/player/state')
|
||||
let 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)
|
||||
}
|
||||
}
|
||||
const state = await response.json()
|
||||
|
||||
// Update all state from backend
|
||||
setIsPlaying(state.is_playing || false)
|
||||
|
||||
Reference in New Issue
Block a user