Forgot to readd join function!
This commit is contained in:
@@ -30,4 +30,33 @@ document.getElementById('create-button').addEventListener('click', async () => {
|
||||
}
|
||||
} catch (_) {
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('join-button').addEventListener('click', async () => {
|
||||
try {
|
||||
const username = getUsername();
|
||||
const roomCode = document.getElementById('room-code-input').value.trim();
|
||||
|
||||
if (!roomCode) {
|
||||
alert("Please enter a room code.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify the room exists by trying to join it
|
||||
const res = await fetch(`/api/room/${roomCode}`, {
|
||||
method: 'GET',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
const allUsernames = JSON.parse(localStorage.getItem('usernames') || '{}');
|
||||
allUsernames[roomCode] = pendingUsername;
|
||||
localStorage.setItem('usernames', JSON.stringify(allUsernames));
|
||||
|
||||
window.location.href = `/room/${roomCode}`;
|
||||
} else {
|
||||
alert("Room not found or invalid code.");
|
||||
}
|
||||
} catch (_) {
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user