Save collapsed state to localstorage
This commit is contained in:
parent
039c12266a
commit
6195e5d8f6
@ -11,6 +11,7 @@ const condensed = require("./condensed");
|
|||||||
const JoinChannel = require("./join-channel");
|
const JoinChannel = require("./join-channel");
|
||||||
const helpers_parse = require("./libs/handlebars/parse");
|
const helpers_parse = require("./libs/handlebars/parse");
|
||||||
const Userlist = require("./userlist");
|
const Userlist = require("./userlist");
|
||||||
|
const storage = require("./localStorage");
|
||||||
|
|
||||||
const chat = $("#chat");
|
const chat = $("#chat");
|
||||||
const sidebar = $("#sidebar");
|
const sidebar = $("#sidebar");
|
||||||
@ -195,6 +196,8 @@ function renderChannelUsers(data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderNetworks(data, singleNetwork) {
|
function renderNetworks(data, singleNetwork) {
|
||||||
|
const collapsed = new Set(JSON.parse(storage.get("thelounge.networks.collapsed")));
|
||||||
|
|
||||||
sidebar.find(".empty").hide();
|
sidebar.find(".empty").hide();
|
||||||
sidebar.find(".networks").append(
|
sidebar.find(".networks").append(
|
||||||
templates.network({
|
templates.network({
|
||||||
@ -202,6 +205,10 @@ function renderNetworks(data, singleNetwork) {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
collapsed.forEach((key) => {
|
||||||
|
collapseNetwork($(`.network[data-uuid="${key}"] button.collapse-network`));
|
||||||
|
});
|
||||||
|
|
||||||
// Add keyboard handlers to the "Join a channel…" form inputs/button
|
// Add keyboard handlers to the "Join a channel…" form inputs/button
|
||||||
JoinChannel.handleKeybinds();
|
JoinChannel.handleKeybinds();
|
||||||
|
|
||||||
@ -305,8 +312,12 @@ function loadMoreHistory(entries) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
sidebar.on("click", ".collapse-network", (e) => {
|
sidebar.on("click", "button.collapse-network", (e) => collapseNetwork($(e.target)));
|
||||||
const collapseButton = $(e.target);
|
|
||||||
|
function collapseNetwork(target) {
|
||||||
|
const collapseButton = target.closest(".collapse-network");
|
||||||
|
const networks = new Set(JSON.parse(storage.get("thelounge.networks.collapsed")));
|
||||||
|
const networkuuid = collapseButton.closest(".network").data("uuid");
|
||||||
|
|
||||||
if (collapseButton.closest(".network").find(".active").length > 0) {
|
if (collapseButton.closest(".network").find(".active").length > 0) {
|
||||||
collapseButton.closest(".lobby").click();
|
collapseButton.closest(".lobby").click();
|
||||||
@ -317,10 +328,13 @@ sidebar.on("click", ".collapse-network", (e) => {
|
|||||||
if (collapseButton.attr("aria-expanded") === "true") {
|
if (collapseButton.attr("aria-expanded") === "true") {
|
||||||
collapseButton.attr("aria-expanded", false);
|
collapseButton.attr("aria-expanded", false);
|
||||||
collapseButton.attr("aria-label", "Expand");
|
collapseButton.attr("aria-label", "Expand");
|
||||||
|
networks.add(networkuuid);
|
||||||
} else {
|
} else {
|
||||||
collapseButton.attr("aria-expanded", true);
|
collapseButton.attr("aria-expanded", true);
|
||||||
collapseButton.attr("aria-label", "Collapse");
|
collapseButton.attr("aria-label", "Collapse");
|
||||||
|
networks.delete(networkuuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
storage.set("thelounge.networks.collapsed", JSON.stringify([...networks]));
|
||||||
return false;
|
return false;
|
||||||
});
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
id="network-{{id}}"
|
id="network-{{id}}"
|
||||||
class="network name-{{slugify name}} {{#if serverOptions.NETWORK}}network-{{slugify serverOptions.NETWORK}}{{/if}} {{#unless status.connected}}not-connected{{/unless}} {{#unless status.secure}}not-secure{{/unless}}"
|
class="network name-{{slugify name}} {{#if serverOptions.NETWORK}}network-{{slugify serverOptions.NETWORK}}{{/if}} {{#unless status.connected}}not-connected{{/unless}} {{#unless status.secure}}not-secure{{/unless}}"
|
||||||
data-id="{{id}}"
|
data-id="{{id}}"
|
||||||
|
data-uuid="{{uuid}}"
|
||||||
data-nick="{{nick}}"
|
data-nick="{{nick}}"
|
||||||
data-options="{{tojson serverOptions}}"
|
data-options="{{tojson serverOptions}}"
|
||||||
role="region"
|
role="region"
|
||||||
|
Loading…
Reference in New Issue
Block a user