refactor: simplify initial state fetching in MusicPlayerProvider
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user