diff --git a/gulpfile.js b/gulpfile.js index 4cc60c417..e66f96313 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -114,6 +114,7 @@ const refactoredSrc = [ "./src/js/tribe/matchmaking.js", "./src/js/tribe/tribe-default-configs.js", "./src/js/tribe/tribe.js", + "./src/js/tribe/tribe-online-stats.js", "./src/js/account/all-time-stats.js", "./src/js/account/pb-tables.js", diff --git a/src/js/tribe/tribe-online-stats.js b/src/js/tribe/tribe-online-stats.js new file mode 100644 index 000000000..bedb6bc04 --- /dev/null +++ b/src/js/tribe/tribe-online-stats.js @@ -0,0 +1,22 @@ +import * as Tribe from "./tribe"; + +export function showLoading() { + $(".pageTribe .prelobby .welcome .onlineStatsLoader").removeClass("hidden"); +} + +export function hideLoading() { + $(".pageTribe .prelobby .welcome .onlineStatsLoader").addClass("hidden"); +} + +export function refresh() { + showLoading(); + Tribe.socket.emit("mp_get_online_stats"); + if ( + $(".pageTribe").hasClass("active") && + !$(".pageTribe .prelobby").hasClass("hidden") + ) { + setTimeout(() => { + refresh(); + }, 10000); + } +} diff --git a/src/js/tribe/tribe.js b/src/js/tribe/tribe.js index 2e613b5e0..8b219c575 100644 --- a/src/js/tribe/tribe.js +++ b/src/js/tribe/tribe.js @@ -13,6 +13,7 @@ import * as TestLogic from "./test-logic"; import * as TestUI from "./test-ui"; import * as Commandline from "./commandline"; import * as CommandlineLists from "./commandline-lists"; +import * as OnlineStats from "./tribe-online-stats"; import seedrandom from "seedrandom"; export let state = -1; @@ -101,7 +102,7 @@ function changeActiveSubpage(newPage) { 250, () => { if (newPage === "prelobby") { - socket.emit("mp_get_online_stats"); + OnlineStats.refresh(); } if (newPage === "lobby") { $(".pageTribe .lobby .chat .input input").focus(); @@ -1000,6 +1001,7 @@ socket.on("mp_room_name_update", (data) => { }); socket.on("mp_update_online_stats", (data) => { + OnlineStats.hideLoading(); $(".pageTribe .prelobby .welcome .stats").empty(); $(".pageTribe .prelobby .welcome .stats").append( `