Skip to content

Commit

Permalink
Implement that toasts are paused when a modal is opened
Browse files Browse the repository at this point in the history
  • Loading branch information
Dlurak committed Jul 1, 2024
1 parent fcbb207 commit 37567d4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/lib/components/layout/toasts/Toast.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import type { Readable } from 'svelte/store';
import { confirmation } from '../confirmation';
import { useLauncher } from '../launcher/hook';
import { openedModals } from '$lib/stores';
export let type: 'success' | 'error' | 'warning' | 'info' = 'success';
export let content: Readable<string>;
Expand All @@ -33,6 +34,7 @@
if (!document.hasFocus()) return true;
if ($confirmation) return true;
if ($isLauncherOpened) return true;
if ($openedModals > 0) return true;
return false;
}
Expand Down
8 changes: 7 additions & 1 deletion src/lib/components/modal/Modal.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { openedModals } from '$lib/stores';
import { enableScrolling } from '$lib/utils/dom/scroll';
import { createEventDispatcher } from 'svelte';
import { Icon, XMark } from 'svelte-hero-icons';
Expand All @@ -11,8 +12,10 @@
export let isOpen = false;
export const open = () => {
console.log('Open inside');
if (!dialogElement) return;
if (dialogElement.open) return;
openedModals.update((x) => x + 1);
dialogElement.showModal();
isOpen = true;
dispatch('open');
Expand All @@ -21,6 +24,9 @@
export const close = () => {
if (!dialogElement) return;
if (!dialogElement.open) return;
openedModals.update((x) => x - 1);
dialogElement.close();
isOpen = false;
dispatch('close');
Expand Down
2 changes: 2 additions & 0 deletions src/lib/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ import { svocal } from './utils/store/svocal';
export const navHeight = writable(0);
export const footerHeight = writable(0);
export const currentLang = svocal('i18n.currentlang');

export const openedModals = writable(0);

0 comments on commit 37567d4

Please sign in to comment.