fixed minor mistake

This commit is contained in:
Karma Riuk
2025-05-20 14:34:17 +02:00
parent 187cde7079
commit 24ef78e615

View File

@ -110,15 +110,21 @@ document.getElementById("upload-btn").onclick = async () => {
[...document.getElementsByClassName("download-results")].forEach((e) => {
e.onclick = () => {
const dataStr =
"data:text/json;charset=utf-8," +
encodeURIComponent(JSON.stringify(results));
const dlAnchorElem = document.createElement("a");
dlAnchorElem.setAttribute("href", dataStr);
dlAnchorElem.setAttribute("download", "results.json");
document.body.appendChild(dlAnchorElem);
dlAnchorElem.click();
document.body.removeChild(dlAnchorElem);
// 1. Convert object to JSON string
const json = JSON.stringify(results, null, 2);
// 2. Create a Blob of type application/json
const blob = new Blob([json], { type: "application/json" });
// 3. Generate a temporary object URL
const url = URL.createObjectURL(blob);
// 4. Create a temporary <a> element and trigger download
const link = document.createElement("a");
link.href = url;
link.download = "results.json";
// document.body.appendChild(link);
link.click();
// 5. Cleanup: revoke the object URL and remove the link
URL.revokeObjectURL(url);
// document.body.removeChild(link);
};
});
@ -185,7 +191,7 @@ socket.on("queue_position", (data) => {
let queue_position_interval = null;
document.getElementById("request-status").onclick = async () => {
if (!id.reportValidity()) return;
if (!uuid.reportValidity()) return;
const res = await fetch(`/answers/status/${uuid.value}`, {
headers: {
"X-Socket-Id": socket.id,
@ -209,6 +215,8 @@ document.getElementById("request-status").onclick = async () => {
if (json.type == "comment") populateCommentTable(json.results);
else if (json.type == "comment") populateRefinementTable(json.results);
else console.error(`Unknown type ${data.type}`);
// set global variable, used when user wants to download results
results = json.results;
} else if (json.status == "waiting") {
statusStatusEl.textContent = `Currently waiting, position in queue ${json.queue_position}`;
queue_position_interval = setInterval(() => {