From 181a307bcb6a751fd56bfa4dc2624d1b9dbae294 Mon Sep 17 00:00:00 2001 From: Seth Date: Wed, 30 Aug 2023 08:47:42 +0800 Subject: [PATCH] fix: adjust left bar's width when changing graph --- package.json | 2 +- src/plugin.tsx | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index bd35909..2d58a1d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "logseq-plugin-favorite-tree", - "version": "1.0.2", + "version": "1.0.3", "main": "dist/index.html", "logseq": { "id": "_sethyuan-logseq-favorite-tree", diff --git a/src/plugin.tsx b/src/plugin.tsx index b6bdc2d..db61ba2 100644 --- a/src/plugin.tsx +++ b/src/plugin.tsx @@ -79,16 +79,10 @@ async function main() { const transactionOff = logseq.DB.onChanged(onTransaction) - await processFavorites() + const graphOff = logseq.App.onCurrentGraphChanged(adjustLeftBarWidth) - const graph = (await logseq.App.getCurrentGraph())! - const storedWidth = parent.localStorage.getItem(`kef-ft-lsw-${graph.name}`) - if (storedWidth) { - parent.document.documentElement.style.setProperty( - "--ls-left-sidebar-width", - `${+storedWidth}px`, - ) - } + await processFavorites() + await adjustLeftBarWidth() logseq.provideUI({ key: "kef-ft-drag-handle", @@ -103,6 +97,7 @@ async function main() { }, 0) logseq.beforeunload(async () => { + graphOff() transactionOff() favoritesObserver.disconnect() dragHandle?.removeEventListener("pointerdown", onPointerDown) @@ -233,6 +228,17 @@ async function onTransaction({ blocks, txData, txMeta }: any) { } } +async function adjustLeftBarWidth() { + const graph = (await logseq.App.getCurrentGraph())! + const storedWidth = parent.localStorage.getItem(`kef-ft-lsw-${graph.name}`) + if (storedWidth) { + parent.document.documentElement.style.setProperty( + "--ls-left-sidebar-width", + `${+storedWidth}px`, + ) + } +} + function needsProcessing(txData: any[]) { const hierarchyProperty = logseq.settings?.hierarchyProperty ?? "tags" let oldProperty, newProperty