express: ready for voting, but the /results display is not good

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2023-09-15 09:37:35 -04:00
parent e3150bd53b
commit 5c4e28e2de
Signed by: vbatts
GPG key ID: E30EFAA812C6E5ED
4 changed files with 83 additions and 5 deletions

View file

@ -30,7 +30,10 @@ function getSessionId() {
}
function clearSessionId() {
document.cookie = ``;
const newSessionId = generateSessionId();
document.cookie = `sessionId=${newSessionId}`;
setSessionStartTime();
getSessionId();
}
// Function to set session start time
@ -58,6 +61,7 @@ document.getElementById('isNotCritterButton').addEventListener('click', () => {
document.getElementById('startOverButton').addEventListener('click', () => {
clearSessionId();
getNextAnimal();
});
// Function to record button clicks on the server
@ -68,12 +72,14 @@ async function recordButtonClick(buttonName, sessionId) {
const timeDifference = currentTime - lastButtonClickTime;
// Include the time difference in the POST request data
const animal = document.getElementById('animal-name').textContent;
const bodyData = JSON.stringify({ "animal": animal, "button": buttonName, "session": sessionId, "difference": timeDifference, "time": sessionStartTime });
console.log(bodyData);
await fetch('/recordButtonClick', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ "animal": animal, "button": buttonName, "session": sessionId, "difference": timeDifference, "time": sessionStartTime }),
body: bodyData,
});
}
lastButtonClickTime = currentTime; // Record the timestamp of the button click