refactor: remove console logs for cleaner code and improved readability

This commit is contained in:
JSC
2025-07-07 21:18:00 +02:00
parent 2230fa32e5
commit 32fab283be
5 changed files with 8 additions and 102 deletions

View File

@@ -90,38 +90,22 @@ export function MusicPlayerProvider({ children }: MusicPlayerProviderProps) {
useEffect(() => {
const fetchInitialState = async () => {
try {
console.log('🎵 MusicPlayerContext: Fetching initial player state...')
const response = await apiService.get('/api/player/state')
const state = await response.json()
console.log('🎵 MusicPlayerContext: Initial state received', {
playlist_id: state.playlist_id,
is_playing: state.is_playing,
current_time: state.current_time,
duration: state.duration,
playlist_length: state.playlist?.length
})
let state = await response.json()
// If no playlist is loaded, try to load the main playlist
if (!state.playlist_id) {
console.log('🎵 MusicPlayerContext: No playlist loaded, attempting to load main playlist...')
try {
await apiService.post('/api/player/load-main-playlist')
// Fetch state again after loading main playlist
const newResponse = await apiService.get('/api/player/state')
const newState = await newResponse.json()
console.log('🎵 MusicPlayerContext: Main playlist loaded, new state:', {
playlist_id: newState.playlist_id,
playlist_length: newState.playlist?.length
})
state = newState
state = await newResponse.json()
} catch (loadError) {
console.warn('🎵 MusicPlayerContext: Failed to load main playlist:', loadError)
console.warn('Failed to load main playlist:', loadError)
}
}
// Update all state from backend
console.log('🎵 MusicPlayerContext: Updating initial state in React')
setIsPlaying(state.is_playing || false)
setCurrentTime(state.current_time || 0)
setDuration(state.duration || 0)
@@ -133,9 +117,8 @@ export function MusicPlayerProvider({ children }: MusicPlayerProviderProps) {
setCurrentPlaylistId(state.playlist_id || null)
setCurrentTrack(state.current_track || null)
console.log('🎵 MusicPlayerContext: Initial state setup complete')
} catch (error) {
console.error('❌ MusicPlayerContext: Failed to fetch initial player state:', error)
console.error('Failed to fetch initial player state:', error)
}
}
@@ -144,23 +127,11 @@ export function MusicPlayerProvider({ children }: MusicPlayerProviderProps) {
// Listen for real-time player updates via SocketIO
useEffect(() => {
console.log('🎵 MusicPlayerContext: Setting up SocketIO listeners', { hasSocket: !!socket });
if (!socket) {
console.log('⏳ MusicPlayerContext: No socket available yet');
return;
}
const handlePlayerStateUpdate = (state: any) => {
console.log('🎵 MusicPlayerContext: Received player state update', {
is_playing: state.is_playing,
current_time: state.current_time,
duration: state.duration,
volume: state.volume,
current_track: state.current_track?.title,
playlist_length: state.playlist?.length
});
setIsPlaying(state.is_playing || false)
setCurrentTime(state.current_time || 0)
setDuration(state.duration || 0)
@@ -173,11 +144,9 @@ export function MusicPlayerProvider({ children }: MusicPlayerProviderProps) {
setCurrentTrack(state.current_track || null)
}
console.log('🎵 MusicPlayerContext: Registering player_state_update listener');
socket.on('player_state_update', handlePlayerStateUpdate)
return () => {
console.log('🎵 MusicPlayerContext: Cleaning up SocketIO listeners');
socket.off('player_state_update', handlePlayerStateUpdate)
}
}, [socket])