Save collapsed state to localstorage

This commit is contained in:
Al McKinlay 2018-03-15 09:18:06 +00:00 committed by Alistair McKinlay
parent 039c12266a
commit 6195e5d8f6
2 changed files with 18 additions and 3 deletions

View file

@ -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;
});
}

View file

@ -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"