From 8bae940df52a9f490cc4f92fe778184b405d682d Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Tue, 5 Nov 2024 12:07:05 -0600 Subject: [PATCH 1/2] refine global event store --- src/lib/helpers/store.js | 11 ++++++++++- src/routes/VerticalLayout/Sidebar.svelte | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/lib/helpers/store.js b/src/lib/helpers/store.js index 7b2677e..328cbb4 100644 --- a/src/lib/helpers/store.js +++ b/src/lib/helpers/store.js @@ -9,7 +9,16 @@ const conversationSearchOptionKey = "conversation_search_option"; const conversationUserMessageKey = "conversation_user_messages"; /** @type {Writable} */ -export const globalEventStore = writable({ name: "", payload: {} }); +const createGlobalEventStore = () => { + const { subscribe, set } = writable({ name: "", payload: {} }); + return { + subscribe, + set, + reset: () => set({}) + }; +} + +export const globalEventStore = createGlobalEventStore(); /** @type {Writable} */ diff --git a/src/routes/VerticalLayout/Sidebar.svelte b/src/routes/VerticalLayout/Sidebar.svelte index 479127f..66d83c1 100644 --- a/src/routes/VerticalLayout/Sidebar.svelte +++ b/src/routes/VerticalLayout/Sidebar.svelte @@ -8,6 +8,7 @@ import { page } from '$app/stores'; import { browser } from '$app/environment'; import { _ } from 'svelte-i18n'; + import { globalEventStore } from '$lib/helpers/store'; /** @type {import('$pluginTypes').PluginMenuDefModel[]} */ export let menu; @@ -199,6 +200,14 @@ const path = $page.url.pathname; return path?.startsWith('/') ? path.substring(1) : path; }; + + /** @param {string} link */ + const goToPage = (link) => { + if (!link) return; + + globalEventStore.reset(); + window.open(link, '_self'); + }
@@ -225,19 +234,19 @@ {:else} -
  • {$_(subMenu.label)}
  • +
  • goToPage(subMenu.link)}>{$_(subMenu.label)}
  • {/if} {/each} {:else}
  • - + goToPage(item.link)} > {$_(item.label)}
  • From e9852aa70d3153bab755799d2fdd7bd336f3130f Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Tue, 5 Nov 2024 12:10:50 -0600 Subject: [PATCH 2/2] minor change --- src/routes/VerticalLayout/Sidebar.svelte | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/routes/VerticalLayout/Sidebar.svelte b/src/routes/VerticalLayout/Sidebar.svelte index 66d83c1..5084b90 100644 --- a/src/routes/VerticalLayout/Sidebar.svelte +++ b/src/routes/VerticalLayout/Sidebar.svelte @@ -203,10 +203,7 @@ /** @param {string} link */ const goToPage = (link) => { - if (!link) return; - globalEventStore.reset(); - window.open(link, '_self'); } @@ -234,19 +231,19 @@ {:else} -
  • goToPage(subMenu.link)}>{$_(subMenu.label)}
  • +
  • goToPage(subMenu.link)}>{$_(subMenu.label)}
  • {/if} {/each} {:else}
  • - goToPage(item.link)} > + goToPage(item.link)} > {$_(item.label)}