Merge pull request #3299 from thelounge/xpaw/fix-sync-sort

Fix channel sorting to work across clients on Vue
This commit is contained in:
Pavel Djundik 2019-07-15 10:33:37 +03:00 committed by GitHub
commit eac4fb73f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,39 +1,27 @@
"use strict"; "use strict";
const $ = require("jquery");
const socket = require("../socket"); const socket = require("../socket");
const {vueApp} = require("../vue");
socket.on("sync_sort", function(data) { socket.on("sync_sort", function(data) {
const type = data.type;
const order = data.order; const order = data.order;
const container = $(".networks");
const network = container.find(`.network[data-uuid="${data.target}"]`);
if (type === "networks") { switch (data.type) {
$.each(order, function(index, value) { case "networks":
const position = $(container.children(".network")[index]); vueApp.networks.sort((a, b) => order.indexOf(a.uuid) - order.indexOf(b.uuid));
if (Number(position.attr("data-id")) === value) { // Network in correct place break;
return true; // No point in continuing
}
network.insertBefore(position); case "channels": {
}); const network = vueApp.networks.find((n) => n.uuid === data.target);
} 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
}
const position = $(network.children(".chan")[index]); // Target channel at position if (!network) {
return;
}
if (Number(position.attr("data-id")) === value) { // Channel in correct place network.channels.sort((a, b) => order.indexOf(a.id) - order.indexOf(b.id));
return true; // No point in continuing
}
const channel = network.find(".chan[data-id=" + value + "]"); // Channel at position break;
}
channel.insertBefore(position);
});
} }
}); });