From 01fc26d2c0453b5dec70669b8cadd0622b64036c Mon Sep 17 00:00:00 2001 From: MarcRez33 <59151753+MarcRez33@users.noreply.github.com> Date: Sat, 31 Aug 2024 21:25:30 +0200 Subject: [PATCH] fix: Reload graph after a theme change (closes #1380) (#1383) * FIX: Reload graph after a theme change * FIX: Reload graph after a theme change - comment updated * FIX: Reload graph after a theme change - comment updated * FIX: Reload graph after a theme change * fix: Reload graph after a theme change --- quartz/components/scripts/graph.inline.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/quartz/components/scripts/graph.inline.ts b/quartz/components/scripts/graph.inline.ts index 6bf43aa..5e8d48c 100644 --- a/quartz/components/scripts/graph.inline.ts +++ b/quartz/components/scripts/graph.inline.ts @@ -550,6 +550,19 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => { addToVisited(simplifySlug(slug)) await renderGraph("graph-container", slug) + // Function to re-render the graph when the theme changes + const handleThemeChange = () => { + renderGraph("graph-container", slug) + } + + // event listener for theme change + document.addEventListener("themechange", handleThemeChange) + + // cleanup for the event listener + window.addCleanup(() => { + document.removeEventListener("themechange", handleThemeChange) + }) + const container = document.getElementById("global-graph-outer") const sidebar = container?.closest(".sidebar") as HTMLElement