From a62546180065c2f7ce8ee01c70203ba5bcb26e8b Mon Sep 17 00:00:00 2001 From: Miodec Date: Fri, 5 Feb 2021 04:06:38 +0000 Subject: [PATCH] fixed graphs duplicating --- src/js/misc.js | 14 ++++++++++++++ src/js/tribe.js | 11 +++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/js/misc.js b/src/js/misc.js index 73896f1c5..7e5cce53d 100644 --- a/src/js/misc.js +++ b/src/js/misc.js @@ -585,3 +585,17 @@ export function cleanTypographySymbols(textToClean) { }; return textToClean.replace(/[“”’‘—,…«»–]/g, (char) => specials[char] || ""); } + +function forEachWithCallback(callback) { + const arrayCopy = this; + let index = 0; + const next = () => { + index++; + if (arrayCopy.length > 0) { + callback(arrayCopy.shift(), index, next); + } + }; + next(); +} + +Array.prototype.forEachWithCallback = forEachWithCallback; diff --git a/src/js/tribe.js b/src/js/tribe.js index f53779416..1ccb0be41 100644 --- a/src/js/tribe.js +++ b/src/js/tribe.js @@ -1141,14 +1141,17 @@ MP.socket.on("mp_room_user_finished", (data) => { if (data.sid === MP.socket.id) { MP.room.userFinished = true; - Object.keys(MP.room.userGraphs).forEach((sid) => { - let userGraph = MP.room.userGraphs[sid]; - userGraph.graph = drawMinigraph(sid, userGraph.data); + Object.keys(MP.room.userGraphs).forEachWithCallback((sid, i, next) => { + setTimeout(() => { + let userGraph = MP.room.userGraphs[sid]; + userGraph.graph = drawMinigraph(sid, userGraph.data); + next(); + }, 1); }); } else if (MP.room.userFinished) { MP.room.userGraphs[data.sid].graph = drawMinigraph(data.sid, data.result); } - }, 500); + }, 250); // $(`.tribeResult table .player[sid=${data.sid}] .progress`), // swapElements(