Merge pull request #2195 from thelounge/mcinkay/collapse-state
Save collapsed state to localstorage
This commit is contained in:
commit
e43c591890
@ -11,6 +11,7 @@ const condensed = require("./condensed");
|
||||
const JoinChannel = require("./join-channel");
|
||||
const helpers_parse = require("./libs/handlebars/parse");
|
||||
const Userlist = require("./userlist");
|
||||
const storage = require("./localStorage");
|
||||
|
||||
const chat = $("#chat");
|
||||
const sidebar = $("#sidebar");
|
||||
@ -195,6 +196,8 @@ function renderChannelUsers(data) {
|
||||
}
|
||||
|
||||
function renderNetworks(data, singleNetwork) {
|
||||
const collapsed = new Set(JSON.parse(storage.get("thelounge.networks.collapsed")));
|
||||
|
||||
sidebar.find(".empty").hide();
|
||||
sidebar.find(".networks").append(
|
||||
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
|
||||
JoinChannel.handleKeybinds();
|
||||
|
||||
@ -305,8 +312,12 @@ function loadMoreHistory(entries) {
|
||||
});
|
||||
}
|
||||
|
||||
sidebar.on("click", ".collapse-network", (e) => {
|
||||
const collapseButton = $(e.target);
|
||||
sidebar.on("click", "button.collapse-network", (e) => collapseNetwork($(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) {
|
||||
collapseButton.closest(".lobby").click();
|
||||
@ -317,10 +328,13 @@ sidebar.on("click", ".collapse-network", (e) => {
|
||||
if (collapseButton.attr("aria-expanded") === "true") {
|
||||
collapseButton.attr("aria-expanded", false);
|
||||
collapseButton.attr("aria-label", "Expand");
|
||||
networks.add(networkuuid);
|
||||
} else {
|
||||
collapseButton.attr("aria-expanded", true);
|
||||
collapseButton.attr("aria-label", "Collapse");
|
||||
networks.delete(networkuuid);
|
||||
}
|
||||
|
||||
storage.set("thelounge.networks.collapsed", JSON.stringify([...networks]));
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
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}}"
|
||||
data-id="{{id}}"
|
||||
data-uuid="{{uuid}}"
|
||||
data-nick="{{nick}}"
|
||||
data-options="{{tojson serverOptions}}"
|
||||
role="region"
|
||||
|
Loading…
Reference in New Issue
Block a user