Skip to content

Commit

Permalink
Save data even if user playedBefore
Browse files Browse the repository at this point in the history
  • Loading branch information
BraydenKO committed Jan 2, 2025
1 parent 0ce800f commit 950e22e
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,26 +142,22 @@ <h1 id="title">Mouse Follower Game</h1>
localStorage.setItem("playedBefore", playedBefore);

if (inputDevice && playedBefore && age && handedness && gender) { // If all options are selected
if (playedBefore === "no") { // If the user has not played before upload the data
try {
await setDoc(doc(db, "game_inputs", auth.currentUser.uid), {
inputDevice,
playedBefore,
age,
handedness,
gender,
uid: auth.currentUser.uid,
timestamp: Timestamp.fromDate(new Date())
});
console.log("Data saved!");
window.location.href = 'game.html';
} catch (error) {
console.error("Firestore write error:", error.message);
console.error("Error details:", error);
alert("Error saving data. Please try again.");
}
} else { // Let the user play but don't upload data
try {
await setDoc(doc(db, "game_inputs", auth.currentUser.uid), {
inputDevice,
playedBefore,
age,
handedness,
gender,
uid: auth.currentUser.uid,
timestamp: Timestamp.fromDate(new Date())
});
console.log("Data saved!");
window.location.href = 'game.html';
} catch (error) {
console.error("Firestore write error:", error.message);
console.error("Error details:", error);
alert("Error saving data. Please try again.");
}
} else {
alert("Please answer all questions.");
Expand Down

0 comments on commit 950e22e

Please sign in to comment.