fix: adjust left bar's width when changing graph

This commit is contained in:
Seth 2023-08-30 08:47:42 +08:00
parent 97ee47707e
commit 181a307bcb
2 changed files with 16 additions and 10 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "logseq-plugin-favorite-tree", "name": "logseq-plugin-favorite-tree",
"version": "1.0.2", "version": "1.0.3",
"main": "dist/index.html", "main": "dist/index.html",
"logseq": { "logseq": {
"id": "_sethyuan-logseq-favorite-tree", "id": "_sethyuan-logseq-favorite-tree",

View File

@ -79,16 +79,10 @@ async function main() {
const transactionOff = logseq.DB.onChanged(onTransaction) const transactionOff = logseq.DB.onChanged(onTransaction)
await processFavorites() const graphOff = logseq.App.onCurrentGraphChanged(adjustLeftBarWidth)
const graph = (await logseq.App.getCurrentGraph())! await processFavorites()
const storedWidth = parent.localStorage.getItem(`kef-ft-lsw-${graph.name}`) await adjustLeftBarWidth()
if (storedWidth) {
parent.document.documentElement.style.setProperty(
"--ls-left-sidebar-width",
`${+storedWidth}px`,
)
}
logseq.provideUI({ logseq.provideUI({
key: "kef-ft-drag-handle", key: "kef-ft-drag-handle",
@ -103,6 +97,7 @@ async function main() {
}, 0) }, 0)
logseq.beforeunload(async () => { logseq.beforeunload(async () => {
graphOff()
transactionOff() transactionOff()
favoritesObserver.disconnect() favoritesObserver.disconnect()
dragHandle?.removeEventListener("pointerdown", onPointerDown) 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[]) { function needsProcessing(txData: any[]) {
const hierarchyProperty = logseq.settings?.hierarchyProperty ?? "tags" const hierarchyProperty = logseq.settings?.hierarchyProperty ?? "tags"
let oldProperty, newProperty let oldProperty, newProperty