*.js: WIP changes for session handling, but ...
Some checks failed
Basic Checking / Explore-Gitea-Actions (push) Failing after 42s

/newSession is still not right. It seems to work right the first time,
but then is an error...

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2023-09-29 16:34:41 -04:00
parent b41568337b
commit 523b979764
Signed by: vbatts
GPG key ID: E30EFAA812C6E5ED
3 changed files with 23 additions and 36 deletions

View file

@ -13,18 +13,6 @@ async function getNextAnimal () {
}
}
// Function to set or retrieve the session ID cookie
function getSessionId () {
const sessionId = document.cookie.replace(
/(?:(?:^|.*;\s*)sessionId\s*=\s*([^;]*).*$)|^.*$/,
'$1'
)
if (!sessionId) {
return newSession()
}
return sessionId
}
async function newSession () {
setSessionStartTime()
try {
@ -34,7 +22,6 @@ async function newSession () {
} catch (error) {
console.error('Error fetching data:', error)
}
getSessionId()
}
// Function to set session start time
@ -52,7 +39,7 @@ function displayTimeDifference () {
}
// Function to record button clicks on the server
async function recordButtonClick (buttonName, sessionId) {
async function recordButtonClick (buttonName) {
try {
const currentTime = new Date()
if (lastButtonClickTime) {
@ -62,7 +49,6 @@ async function recordButtonClick (buttonName, sessionId) {
const bodyData = JSON.stringify({
animal,
button: buttonName,
session: sessionId,
difference: timeDifference,
time: sessionStartTime
})
@ -86,11 +72,11 @@ async function recordButtonClick (buttonName, sessionId) {
// Add click event listeners to the buttons
document.getElementById('isCritterButton').addEventListener('click', () => {
recordButtonClick('is critter', getSessionId())
recordButtonClick('is critter')
})
document.getElementById('isNotCritterButton').addEventListener('click', () => {
recordButtonClick('is not critter', getSessionId())
recordButtonClick('is not critter')
})
document.getElementById('startOverButton').addEventListener('click', () => {