From db6e5898df0282893ed7c5860c5248385ca4e3fa Mon Sep 17 00:00:00 2001 From: Webifi Date: Mon, 5 Jun 2023 16:51:11 -0500 Subject: [PATCH] Close all modals on route change --- src/App.svelte | 12 ++++++++++-- src/lib/Util.svelte | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/App.svelte b/src/App.svelte index 314c726..9ce248d 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -9,7 +9,7 @@ import NewChat from './lib/NewChat.svelte' import { chatsStorage, apiKeyStorage } from './lib/Storage.svelte' import { Modals, closeModal } from 'svelte-modals' - import { triggerModalEsc } from './lib/Util.svelte' + import { dispatchModalEsc, checkModalEsc } from './lib/Util.svelte' // The definition of the routes with some conditions const routes = { @@ -31,6 +31,14 @@ '*': Home } + + const onLocationChange = (...args:any) => { + // close all modals on route change + dispatchModalEsc() + } + + $: onLocationChange($location) + @@ -53,7 +61,7 @@ triggerModalEsc(e)} + on:keydown={(e) => checkModalEsc(e)} />