mirror of
https://github.com/karma-riuk/crab-webapp.git
synced 2025-07-05 06:08:13 +02:00
created a websocket to witness the progress of the processing
This commit is contained in:
26
public/js/socket.js
Normal file
26
public/js/socket.js
Normal file
@ -0,0 +1,26 @@
|
||||
const socket = io();
|
||||
|
||||
// 2) Grab our new DOM elements
|
||||
const progressContainer = document.getElementById("progress-container");
|
||||
const progressBar = document.getElementById("progress-bar");
|
||||
const progressText = document.getElementById("progress-text");
|
||||
const statusEl = document.getElementById("status");
|
||||
|
||||
function setProgress(percent) {
|
||||
progressBar.value = percent;
|
||||
progressText.textContent = `${percent}%`;
|
||||
}
|
||||
|
||||
// 3) Update UI on each progress message
|
||||
socket.on("progress", (data) => {
|
||||
setProgress(data.percent);
|
||||
if (data.percent == 100) {
|
||||
statusEl.style.color = "green";
|
||||
statusEl.textContent = "Processing complete!";
|
||||
}
|
||||
});
|
||||
|
||||
socket.on("started-processing", () => {
|
||||
progressContainer.style.display = "block";
|
||||
setProgress(0);
|
||||
});
|
Reference in New Issue
Block a user