*: stubbing out a page for "what's this about?"
All checks were successful
Basic Checking / Explore-Gitea-Actions (push) Successful in 28s

Fixes #2

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2023-09-28 16:57:48 -04:00
parent 31408d4536
commit dbc7509fbd
Signed by: vbatts
GPG key ID: E30EFAA812C6E5ED
5 changed files with 69 additions and 6 deletions

108
wwwroot/asset/frontend.js Normal file
View file

@ -0,0 +1,108 @@
// Initialize session variables
let sessionStartTime;
let lastButtonClickTime;
// Function to generate a random session ID
function generateSessionId() {
return (
Math.random().toString(36).substring(2, 15) +
Math.random().toString(36).substring(2, 15)
);
}
// Function to fetch a random animal name from the server
async function getNextAnimal() {
try {
const response = await fetch("/getNextAnimal");
const data = await response.json();
document.getElementById("animal-name").textContent = data.animalName;
} catch (error) {
console.error("Error fetching data:", error);
}
}
// Function to set or retrieve the session ID cookie
function getSessionId() {
const sessionId = document.cookie.replace(
/(?:(?:^|.*;\s*)sessionId\s*=\s*([^;]*).*$)|^.*$/,
"$1",
);
if (!sessionId) {
const newSessionId = generateSessionId();
document.cookie = `sessionId=${newSessionId}`;
return newSessionId;
}
return sessionId;
}
function clearSessionId() {
const newSessionId = generateSessionId();
document.cookie = `sessionId=${newSessionId}`;
setSessionStartTime();
getSessionId();
}
// Function to set session start time
function setSessionStartTime() {
sessionStartTime = new Date();
}
// Function to calculate and display time difference
function displayTimeDifference() {
if (sessionStartTime && lastButtonClickTime) {
const timeDifference = lastButtonClickTime - sessionStartTime;
console.log(`Time since session start: ${timeDifference} milliseconds`);
// You can display the time difference on the page as needed
}
}
// Add click event listeners to the buttons
document.getElementById("isCritterButton").addEventListener("click", () => {
recordButtonClick("is critter", getSessionId());
});
document.getElementById("isNotCritterButton").addEventListener("click", () => {
recordButtonClick("is not critter", getSessionId());
});
document.getElementById("startOverButton").addEventListener("click", () => {
clearSessionId();
getNextAnimal();
});
// Function to record button clicks on the server
async function recordButtonClick(buttonName, sessionId) {
try {
const currentTime = new Date();
if (lastButtonClickTime) {
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: bodyData,
});
}
lastButtonClickTime = currentTime; // Record the timestamp of the button click
displayTimeDifference(); // Calculate and display time difference
// TODO - slight delay before loading next animal, to show the user how long that decision took them
getNextAnimal(); // Load another random animal
} catch (error) {
console.error("Error recording button click:", error);
}
}
// Initial random animal load and session start time
getNextAnimal();
setSessionStartTime();

58
wwwroot/index.html Normal file
View file

@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Is this a Critter?</title>
<meta name="description" content="Is this a critter? Trying to agree on what a critter even is requires a bit of sampling. Help by contributing your vote on what a critter even is."/>
</head>
<body>
<div id="isCritter">
<h3>Is this a Critter?</h3>
<p id="animal-name">what about?:</p>
<button id="isCritterButton">Is Critter</button>
<button id="isNotCritterButton">Is <b>not</b> Critter</button>
</div>
<div id="startOver">
<p>
<button id="startOverButton">Start over</button>
</p>
</div>
<div id="whatsThisAllAbout">
<p>
<a id="whatsThisAllAboutLink" href="what.html">(what's this all about?)</a>
</p>
</div>
<div id="footer">
© 2023. All rights reserved. <a href="mailto:isacritter@hashbangbash.com">isacritter</a>; <a href="https://paypal.me/vbatts/1" target="_blank">keep isacritter alive</a>
</div>
<script src="/asset/frontend.js"></script>
<style type="text/css">
#animal-name {
font-size: 25px;
}
#isCritter {
text-align: center;
}
#startOver {
text-align: center;
}
#whatsThisAllAbout {
text-align: center;
}
#footer {
bottom: 2px;
height: 40px;
margin-top: 40px;
text-align: center;
vertical-align: middle;
position: fixed;
width: 100%;
}
</style>
</body>
</html>

42
wwwroot/what.html Normal file
View file

@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Is this a Critter?</title>
<meta name="description" content="Is this a critter? Trying to agree on what a critter even is requires a bit of sampling. Help by contributing your vote on what a critter even is."/>
</head>
<body>
<div id="isCritter">
<h3>What's this all about?</h3>
</div>
<div id="back">
<p>
<a id="backLink" href="/">(back to the critters)</a>
</p>
</div>
<div id="footer">
© 2023. All rights reserved. <a href="mailto:isacritter@hashbangbash.com">isacritter</a>; <a href="https://paypal.me/vbatts/1" target="_blank">keep isacritter alive</a>
</div>
<style type="text/css">
#isCritter {
text-align: center;
}
#back {
text-align: center;
}
#footer {
bottom: 2px;
height: 40px;
margin-top: 40px;
text-align: center;
vertical-align: middle;
position: fixed;
width: 100%;
}
</style>
</body>
</html>