Skip to content

Commit e2da004

Browse files
authored
Merge pull request #39 from taitelee/dev
Clear Search Bar
2 parents 5a98d62 + 371b98a commit e2da004

File tree

2 files changed

+57
-58
lines changed

2 files changed

+57
-58
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"type": "module",
66
"scripts": {
7-
"dev": "next dev",
7+
"dev": "next dev -H 127.0.0.1",
88
"build": "next build",
99
"start": "next start",
1010
"lint": "next lint"

src/app/session/[id]/client.tsx

+56-57
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export function Song(songProps: { id: string, name: string, addedBy?: string, co
178178

179179
function Queue({isHost, initQueue, socket, username, sid
180180
}: { isHost: boolean, initQueue: any[], socket: any, username: string, sid: string}) {
181+
const [songInput, setSongInput] = useState("");
181182
const [songList, setSongList] = useState<any[]>([]);
182183
const [songQuery, setSongQuery] = useState<any[]>([]);
183184
const [toastMessage, setToastMessage] = useState('');
@@ -273,24 +274,23 @@ function Queue({isHost, initQueue, socket, username, sid
273274
sid: sid,
274275
qlen: songList.length
275276
})
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+
};
294294

295295
// For searching songs
296296
const searchSongs = (input: string) => {
@@ -440,49 +440,48 @@ function Queue({isHost, initQueue, socket, username, sid
440440
</div>
441441
))}
442442
</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-
/>
466443
</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>
467465

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+
))}
484482
</div>
485483
</div>
484+
486485
{toastMessage && <Toast message={toastMessage} onClose={() => setToastMessage('')} />}
487486
</>
488487
);

0 commit comments

Comments
 (0)