From bf2c6a6bcf56c8c505dea285cdbe4cb381b012b2 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Fri, 12 Jul 2019 19:47:29 +0300 Subject: [PATCH] Fix channel sorting to work across clients on Vue --- client/js/socket-events/sync_sort.js | 38 ++++++++++------------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/client/js/socket-events/sync_sort.js b/client/js/socket-events/sync_sort.js index 09c63aed..2339bc89 100644 --- a/client/js/socket-events/sync_sort.js +++ b/client/js/socket-events/sync_sort.js @@ -1,39 +1,27 @@ "use strict"; -const $ = require("jquery"); const socket = require("../socket"); +const {vueApp} = require("../vue"); socket.on("sync_sort", function(data) { - const type = data.type; const order = data.order; - const container = $(".networks"); - const network = container.find(`.network[data-uuid="${data.target}"]`); - if (type === "networks") { - $.each(order, function(index, value) { - const position = $(container.children(".network")[index]); + switch (data.type) { + case "networks": + vueApp.networks.sort((a, b) => order.indexOf(a.uuid) - order.indexOf(b.uuid)); - if (Number(position.attr("data-id")) === value) { // Network in correct place - return true; // No point in continuing - } + break; - network.insertBefore(position); - }); - } else if (type === "channels") { - $.each(order, function(index, value) { - if (index === 0) { // Shouldn't attempt to move lobby - return true; // same as `continue` -> skip to next item - } + case "channels": { + const network = vueApp.networks.find((n) => n.uuid === data.target); - const position = $(network.children(".chan")[index]); // Target channel at position + if (!network) { + return; + } - if (Number(position.attr("data-id")) === value) { // Channel in correct place - return true; // No point in continuing - } + network.channels.sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id)); - const channel = network.find(".chan[data-id=" + value + "]"); // Channel at position - - channel.insertBefore(position); - }); + break; + } } });