From a43867162b706e2dfeb93c85fd75a701d63d6343 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Wed, 20 Nov 2024 09:30:21 +0530 Subject: [PATCH] pm_list: Persist DM section collapsed status across reloads. --- web/src/pm_list.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/web/src/pm_list.ts b/web/src/pm_list.ts index 0c64a8fc09..0bb4219b6f 100644 --- a/web/src/pm_list.ts +++ b/web/src/pm_list.ts @@ -1,7 +1,9 @@ import $ from "jquery"; import _ from "lodash"; +import {z} from "zod"; import type {Filter} from "./filter.ts"; +import {localstorage} from "./localstorage.ts"; import * as pm_list_data from "./pm_list_data.ts"; import * as pm_list_dom from "./pm_list_dom.ts"; import type {PMNode} from "./pm_list_dom.ts"; @@ -16,6 +18,9 @@ let prior_dom: vdom.Tag | undefined; // This module manages the direct messages section in the upper // left corner of the app. This was split out from stream_list.ts. +const ls_key = "private_messages_collapsed_status"; +const ls_schema = z.boolean().default(false); +const ls = localstorage(); let private_messages_collapsed = false; // The direct messages section can be zoomed in to view more messages. @@ -36,6 +41,7 @@ export function set_count(count: number): void { export function close(): void { private_messages_collapsed = true; + ls.set(ls_key, private_messages_collapsed); $("#toggle-direct-messages-section-icon").removeClass("rotate-icon-down"); $("#toggle-direct-messages-section-icon").addClass("rotate-icon-right"); @@ -108,6 +114,7 @@ export function update_private_messages(): void { export function expand(): void { private_messages_collapsed = false; + ls.set(ls_key, private_messages_collapsed); $("#toggle-direct-messages-section-icon").addClass("rotate-icon-down"); $("#toggle-direct-messages-section-icon").removeClass("rotate-icon-right"); @@ -229,6 +236,14 @@ export function clear_search(force_rerender = false): void { } export function initialize(): void { + // Restore collapsed status. + private_messages_collapsed = ls_schema.parse(ls.get(ls_key)); + if (private_messages_collapsed) { + close(); + } else { + expand(); + } + const throttled_update_private_message = _.throttle(update_private_messages, 50); $(".direct-messages-container").on("click", "#show-more-direct-messages", (e) => { e.stopPropagation();