@@ -178,6 +178,7 @@ export function Song(songProps: { id: string, name: string, addedBy?: string, co
178
178
179
179
function Queue ( { isHost, initQueue, socket, username, sid
180
180
} : { isHost : boolean , initQueue : any [ ] , socket : any , username : string , sid : string } ) {
181
+ const [ songInput , setSongInput ] = useState ( "" ) ;
181
182
const [ songList , setSongList ] = useState < any [ ] > ( [ ] ) ;
182
183
const [ songQuery , setSongQuery ] = useState < any [ ] > ( [ ] ) ;
183
184
const [ toastMessage , setToastMessage ] = useState ( '' ) ;
@@ -273,24 +274,23 @@ function Queue({isHost, initQueue, socket, username, sid
273
274
sid : sid ,
274
275
qlen : songList . length
275
276
} )
276
- } )
277
- . then ( ( response ) => {
278
- if ( ! response . ok ) throw Error ( response . statusText ) ;
279
- return response . json ( ) ;
280
- } )
281
- . then ( ( data ) => {
282
- // Add Websocket event to tell server to automatically update queue bc song was successfully received by Spotify API
283
- try {
284
- socket . emit ( 'AddedSong' ) ;
285
- }
286
- catch ( error ) {
287
- console . error ( error )
288
- }
289
- setToastMessage ( ` Successfully added: ${ data . responseBody . songName } ` ) ;
290
- setTimeout ( ( ) => setToastMessage ( '' ) , 3000 ) ; // Auto hide after 3 seconds
291
- } )
292
- . catch ( ( error ) => console . log ( error ) ) ;
293
- } ;
277
+ } ) . then ( ( response ) => {
278
+ if ( ! response . ok ) throw Error ( response . statusText ) ;
279
+ return response . json ( ) ;
280
+ } ) . then ( ( data ) => {
281
+ // Add Websocket event to tell server to automatically update queue bc song was successfully received by Spotify API
282
+ try {
283
+ socket . emit ( 'AddedSong' ) ;
284
+ }
285
+ catch ( error ) {
286
+ console . error ( error )
287
+ }
288
+ setToastMessage ( ` Successfully added: ${ data . responseBody . songName } ` ) ;
289
+ setSongInput ( "" ) ;
290
+ setSongQuery ( [ ] ) ;
291
+ setTimeout ( ( ) => setToastMessage ( '' ) , 3000 ) ; // Auto hide after 3 seconds
292
+ } ) . catch ( ( error ) => console . log ( error ) )
293
+ } ;
294
294
295
295
// For searching songs
296
296
const searchSongs = ( input : string ) => {
@@ -440,49 +440,48 @@ function Queue({isHost, initQueue, socket, username, sid
440
440
</ div >
441
441
) ) }
442
442
</ div >
443
- </ div >
444
-
445
- { /* Search & Add songs */ }
446
- < div
447
- id = "QuerySongWrapper"
448
- style = { {
449
- maxHeight : '500px' ,
450
- overflowY : 'scroll' ,
451
- overflowX : 'hidden' ,
452
- scrollbarWidth : 'none' ,
453
- } }
454
- >
455
- < div id = "AddSong" >
456
- < input
457
- type = "text"
458
- placeholder = "Track Name"
459
- onKeyUp = { ( e : any ) => {
460
- clearTimeout ( timer ) ;
461
- timer = setTimeout ( ( ) => {
462
- searchSongs ( e . target . value ) ;
463
- } , waitTime ) ;
464
- } }
465
- />
466
443
</ div >
444
+
445
+ < div id = "QuerySongWrapper" style = { { maxHeight : '500px' ,
446
+ overflowY : 'scroll' ,
447
+ overflowX : 'hidden' ,
448
+ scrollbarWidth : 'none' ,
449
+ } } >
450
+ < div id = "AddSong" >
451
+ < input
452
+ type = "text"
453
+ placeholder = "Track Name"
454
+ value = { songInput }
455
+ onChange = { ( e : React . ChangeEvent < HTMLInputElement > ) => setSongInput ( e . target . value ) }
456
+ onKeyUp = { ( e : React . KeyboardEvent < HTMLInputElement > ) => {
457
+ clearTimeout ( timer ) ;
458
+ const inputValue = e . currentTarget . value ;
459
+ timer = setTimeout ( ( ) => {
460
+ searchSongs ( inputValue ) ;
461
+ } , waitTime ) ;
462
+ } }
463
+ />
464
+ </ div >
467
465
468
- < div id = "dropdown" style = { { maxHeight : '600px' ,
469
- overflowY : 'scroll' ,
470
- overflowX : 'hidden' ,
471
- scrollbarWidth : 'none' ,
472
- } } >
473
- { songQuery . map ( ( song , index ) => (
474
- < button onClick = { ( ) => { handleAddSong ( song . songId ) } } key = { `${ song . songId } ${ song . placement } ` } className = "lookup-song-button" >
475
- < Song
476
- id = { song . songId }
477
- name = { song . songName }
478
- coverArtURL = { song . albumCover }
479
- artistName = { song . artistName }
480
- spotifyURL = { song . spotifyURL }
481
- />
482
- </ button >
483
- ) ) }
466
+ < div id = "dropdown" style = { { maxHeight : '600px' ,
467
+ overflowY : 'scroll' ,
468
+ overflowX : 'hidden' ,
469
+ scrollbarWidth : 'none' ,
470
+ } } >
471
+ { songQuery . map ( ( song , index ) => (
472
+ < button onClick = { ( ) => { handleAddSong ( song . songId ) } } key = { `${ song . songId } ${ song . placement } ` } className = "lookup-song-button" >
473
+ < Song
474
+ id = { song . songId }
475
+ name = { song . songName }
476
+ coverArtURL = { song . albumCover }
477
+ artistName = { song . artistName }
478
+ spotifyURL = { song . spotifyURL }
479
+ />
480
+ </ button >
481
+ ) ) }
484
482
</ div >
485
483
</ div >
484
+
486
485
{ toastMessage && < Toast message = { toastMessage } onClose = { ( ) => setToastMessage ( '' ) } /> }
487
486
</ >
488
487
) ;
0 commit comments