Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -134,7 +134,6 @@ app.get("/balance", authenticateToken, (request, response) => {
|
|||||||
"bearerAuth": []
|
"bearerAuth": []
|
||||||
}] */
|
}] */
|
||||||
const username = request.user.username;
|
const username = request.user.username;
|
||||||
console.log(username);
|
|
||||||
const allUsers = get_data();
|
const allUsers = get_data();
|
||||||
const me = allUsers.find(u => u.username === username);
|
const me = allUsers.find(u => u.username === username);
|
||||||
if (!me) {
|
if (!me) {
|
||||||
@@ -177,7 +176,6 @@ async function createLobby() {
|
|||||||
let data = await response.json();
|
let data = await response.json();
|
||||||
let lobbyId = data.deck_id
|
let lobbyId = data.deck_id
|
||||||
await fetch(`https://www.deckofcardsapi.com/api/deck/${lobbyId}/pile/players/add/?cards=`)
|
await fetch(`https://www.deckofcardsapi.com/api/deck/${lobbyId}/pile/players/add/?cards=`)
|
||||||
console.log(lobbyId);
|
|
||||||
return lobbyId;
|
return lobbyId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +195,6 @@ async function deleteLobby(id) {
|
|||||||
|
|
||||||
async function joinLobby(lobbyId, player_name) {
|
async function joinLobby(lobbyId, player_name) {
|
||||||
let response = await fetch(`https://www.deckofcardsapi.com/api/deck/${lobbyId}/pile/${player_name}/add/?cards=`)
|
let response = await fetch(`https://www.deckofcardsapi.com/api/deck/${lobbyId}/pile/${player_name}/add/?cards=`)
|
||||||
console.log(response);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,8 +49,6 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Balance error:", error);
|
console.log("Balance error:", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logout
|
|
||||||
logoutButton.addEventListener("click", async (e) => {
|
logoutButton.addEventListener("click", async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
try {
|
try {
|
||||||
@@ -63,14 +61,10 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|||||||
console.log("Logout error:", err);
|
console.log("Logout error:", err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Host Lobby and join immediately
|
|
||||||
hostButton.addEventListener("click", async (e) => {
|
hostButton.addEventListener("click", async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const username = await getUsernameFromToken();
|
const username = await getUsernameFromToken();
|
||||||
if (!username) return alert("User not authenticated");
|
if (!username) return alert("User not authenticated");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/lobby/create?username=${username}`);
|
const res = await fetch(`/lobby/create?username=${username}`);
|
||||||
if (res.redirected) {
|
if (res.redirected) {
|
||||||
@@ -78,10 +72,8 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|||||||
const lobbyId = joinURL.searchParams.get("lobbyId");
|
const lobbyId = joinURL.searchParams.get("lobbyId");
|
||||||
const joinRes = await fetch(joinURL.href);
|
const joinRes = await fetch(joinURL.href);
|
||||||
const {lobbyId: finalLobbyId} = await joinRes.json();
|
const {lobbyId: finalLobbyId} = await joinRes.json();
|
||||||
|
|
||||||
document.getElementById("lobby-id").textContent = finalLobbyId;
|
document.getElementById("lobby-id").textContent = finalLobbyId;
|
||||||
document.getElementById("lobby-room").classList.remove("hidden");
|
document.getElementById("lobby-room").classList.remove("hidden");
|
||||||
|
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
const res = await fetch(`/lobby/players?lobbyId=${finalLobbyId}`);
|
const res = await fetch(`/lobby/players?lobbyId=${finalLobbyId}`);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -108,20 +100,17 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|||||||
const joinError = document.getElementById("join-error");
|
const joinError = document.getElementById("join-error");
|
||||||
joinError.classList.add("hidden"); // hide any previous error
|
joinError.classList.add("hidden"); // hide any previous error
|
||||||
joinError.textContent = "";
|
joinError.textContent = "";
|
||||||
|
|
||||||
if (!lobbyId) {
|
if (!lobbyId) {
|
||||||
joinError.textContent = "Please enter a lobby ID.";
|
joinError.textContent = "Please enter a lobby ID.";
|
||||||
joinError.classList.remove("hidden");
|
joinError.classList.remove("hidden");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const username = await getUsernameFromToken();
|
const username = await getUsernameFromToken();
|
||||||
if (!username) {
|
if (!username) {
|
||||||
joinError.textContent = "User not authenticated.";
|
joinError.textContent = "User not authenticated.";
|
||||||
joinError.classList.remove("hidden");
|
joinError.classList.remove("hidden");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const joinRes = await fetch(`/lobby/join?lobbyId=${lobbyId}&username=${username}`);
|
const joinRes = await fetch(`/lobby/join?lobbyId=${lobbyId}&username=${username}`);
|
||||||
if (joinRes.ok) {
|
if (joinRes.ok) {
|
||||||
|
|||||||
Reference in New Issue
Block a user