@@ -7,6 +7,7 @@ import { v4 as uuidv4 } from "uuid";
7
7
import { ProgressBar , millisecondsToString } from './progressbar' ;
8
8
import { getValue } from '@/src/utils' ;
9
9
import { EndSessionOverlay } from "@/src/app/session/[id]/EndSessionOverlay"
10
+ import { Socket } from 'socket.io-client'
10
11
11
12
12
13
const Toast : React . FC < { message : string ; onClose : ( ) => void ; } > = ( { message, onClose } ) => {
@@ -53,11 +54,10 @@ export function Session ({
53
54
}
54
55
55
56
// A new component for the "now playing" layout
56
- function NowPlayingCard ( { albumCover, trackTitle, artistName, progress, songlength, isPlaying, isHost, onPlayPause, onSkip} : {
57
- albumCover ?: string ; trackTitle ?: string , artistName ?: string , progress : number , songlength : number , isPlaying : boolean , isHost : boolean , onPlayPause : ( ) => void , onSkip : ( ) => void
57
+ function NowPlayingCard ( { albumCover, trackTitle, artistName, progress, songlength, isPlaying, isHost, socket , onPlayPause, onSkip} : {
58
+ albumCover ?: string ; trackTitle ?: string , artistName ?: string , progress : number , songlength : number , isPlaying : boolean , isHost : boolean , socket : any , onPlayPause : ( ) => void , onSkip : ( ) => void
58
59
} ) {
59
60
60
-
61
61
return (
62
62
< div
63
63
className = "now-playing-card"
@@ -301,10 +301,6 @@ function Queue({isHost, initQueue, socket, username, sid
301
301
headers : { 'Content-Type' : 'application/json' } ,
302
302
body : JSON . stringify ( { songName : input , sid : sid } )
303
303
} )
304
- . then ( ( response ) => {
305
- if ( ! response . ok ) throw Error ( response . statusText ) ;
306
- return response . json ( ) ;
307
- } )
308
304
. then ( ( response ) => {
309
305
if ( ! response . ok ) throw Error ( response . statusText ) ;
310
306
return response . json ( ) ;
@@ -323,6 +319,7 @@ function Queue({isHost, initQueue, socket, username, sid
323
319
tmp [ i ] = songProps ;
324
320
}
325
321
// Update UI component with new search data
322
+ console . log ( tmp )
326
323
setSongQuery ( tmp ) ;
327
324
} ) . catch ( ( error ) => console . log ( error ) ) ;
328
325
} ;
@@ -360,13 +357,13 @@ function Queue({isHost, initQueue, socket, username, sid
360
357
361
358
const handleSkip = ( ) => {
362
359
fetch ( `${ process . env . NEXT_PUBLIC_APP_SERVER } /api/spotify/skip` , {
363
- method : 'POST' ,
364
- headers : { 'Content-Type' : 'application/json' } ,
365
- body : JSON . stringify ( { sid : sid } )
360
+ method : 'POST' ,
361
+ headers : { 'Content-Type' : 'application/json' } ,
362
+ body : JSON . stringify ( { sid : sid } )
366
363
} )
367
364
. then ( response => {
368
- if ( ! response . ok ) throw new Error ( 'Skip failed' ) ;
369
- socket . emit ( 'AddedSong' ) ; // Refresh queue
365
+ if ( ! response . ok ) throw new Error ( 'Skip failed' ) ;
366
+ socket . emit ( 'AddedSong' ) ; // Refresh queue
370
367
} )
371
368
. catch ( error => console . error ( 'Skip error:' , error ) ) ;
372
369
} ;
@@ -412,6 +409,7 @@ function Queue({isHost, initQueue, socket, username, sid
412
409
songlength = { songlength }
413
410
isPlaying = { isPlaying }
414
411
isHost = { isHost }
412
+ socket = { socket }
415
413
onPlayPause = { handlePlayPause }
416
414
onSkip = { handleSkip }
417
415
/>
@@ -430,7 +428,7 @@ function Queue({isHost, initQueue, socket, username, sid
430
428
< h1 className = "queue-header" > Queue</ h1 >
431
429
< div id = "SongList" >
432
430
{ upcomingQueue . map ( ( song , index ) => (
433
- < div key = { index } >
431
+ < div key = { ` ${ song . songId } ${ song . placement } ` } >
434
432
< Song
435
433
id = { song . songId }
436
434
name = { song . songName }
@@ -473,7 +471,7 @@ function Queue({isHost, initQueue, socket, username, sid
473
471
scrollbarWidth : 'none' ,
474
472
} } >
475
473
{ songQuery . map ( ( song , index ) => (
476
- < button onClick = { ( ) => { handleAddSong ( song . songId ) } } key = { index } className = "lookup-song-button" >
474
+ < button onClick = { ( ) => { handleAddSong ( song . songId ) } } key = { ` ${ song . songId } ${ song . placement } ` } className = "lookup-song-button" >
477
475
< Song
478
476
id = { song . songId }
479
477
name = { song . songName }
0 commit comments