Skip to content

Commit

Permalink
fix: move window-manager in layout component to ensure window root do…
Browse files Browse the repository at this point in the history
…es not get unmounted when navigating to imprint and back
  • Loading branch information
stefanprobst committed Oct 16, 2023
1 parent 88e7148 commit 46220f0
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 28 deletions.
8 changes: 8 additions & 0 deletions components/app-navigation-menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const emit = defineEmits<{
const { menus } = toRefs(props);
const router = useRouter();
const route = useRoute();
const windowsStore = useWindowsStore();
const { setWindowArrangement } = windowsStore;
const { arrangement: currentArrangement, registry } = storeToRefs(windowsStore);
Expand Down Expand Up @@ -79,6 +82,11 @@ onScopeDispose(() => {
}
item.winbox.focus();
/** Windows are only displayed on `/`. */
if (route.path !== '/') {
void router.push('/');
}
}
"
>
Expand Down
19 changes: 18 additions & 1 deletion layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,31 @@ useHead({
return scripts;
}),
});
/**
* We only want to display windows on the root route.
*
* We always render the window manager in the layout, to avoid remounting the window root,
* and consequently having to manually mount/unmount every single window.
* of every single window.
*/
const isWindowManagerVisible = computed(() => {
return route.path === "/";
});
</script>

<template>
<div class="grid min-h-full grid-rows-[auto_1fr_auto] bg-neutral-50">
<SkipLink :target-id="mainContentId">Skip to main content</SkipLink>

<AppHeader />
<slot />
<MainContent>
<slot />

<div :class="{ hidden: !isWindowManagerVisible }" class="relative isolate grid h-full w-full">
<WindowManager />
</div>
</MainContent>
<AppFooter />

<Toaster />
Expand Down
18 changes: 0 additions & 18 deletions pages/[...404].vue

This file was deleted.

4 changes: 2 additions & 2 deletions pages/imprint.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const imprint = await useFetch(String(createImprintUrl(defaultLocale, redmineId)
</script>

<template>
<MainContent class="prose mx-auto w-full max-w-3xl py-8">
<div class="prose mx-auto w-full max-w-3xl py-8">
<h1>Imprint</h1>
<!-- eslint-disable-next-line vue/no-v-html -->
<div v-if="imprint.data.value" v-html="imprint.data.value" />
</MainContent>
</div>
</template>
7 changes: 1 addition & 6 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,5 @@ definePageMeta({
</script>

<template>
<MainContent>
<h1 class="sr-only">VICAV - Vienna Corpus of Arabic Varieties</h1>
<div class="relative isolate grid h-full w-full">
<WindowManager />
</div>
</MainContent>
<h1 class="sr-only">VICAV - Vienna Corpus of Arabic Varieties</h1>
</template>
5 changes: 4 additions & 1 deletion stores/use-windows-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const useWindowsStore = defineStore("windows", () => {
const arrangement = ref<WindowArrangement>("smart-tile");

const router = useRouter();
const route = useRoute();

function addWindow<Kind extends WindowItemKind>(params: {
id?: string | null;
Expand All @@ -106,7 +107,9 @@ export const useWindowsStore = defineStore("windows", () => {
if (rootElement == null) return;

/** Ensure windows open only on `/`. */
void router.push("/");
if (route.path !== "/") {
void router.push("/");
}

const id = params.id ?? `window-${nanoid()}`;
const { title, kind } = params;
Expand Down

0 comments on commit 46220f0

Please sign in to comment.