From 84e1f54fa05d1272bf075ebdbfd08a69cca1ee95 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 11 Dec 2020 14:24:19 +0000 Subject: [PATCH] Improve navigation when logging in and out, remove need to hard reload the page and replace with smooth transitions --- .../client/src/components/ClientApp.svelte | 6 ++---- packages/client/src/components/Router.svelte | 16 ++++++++++++---- packages/client/src/store/auth.js | 18 +++++++++++++++--- packages/client/src/store/index.js | 6 ++++++ packages/client/src/store/initialise.js | 7 +++++++ packages/client/src/store/routes.js | 2 ++ .../standard-components/src/Navigation.svelte | 4 ++-- 7 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 packages/client/src/store/initialise.js diff --git a/packages/client/src/components/ClientApp.svelte b/packages/client/src/components/ClientApp.svelte index 75061ac327..a7a972a435 100644 --- a/packages/client/src/components/ClientApp.svelte +++ b/packages/client/src/components/ClientApp.svelte @@ -3,7 +3,7 @@ import { setContext, onMount } from "svelte" import Component from "./Component.svelte" import SDK from "../sdk" - import { createDataStore, routeStore, screenStore } from "../store" + import { createDataStore, initialise, screenStore } from "../store" // Provide contexts setContext("sdk", SDK) @@ -14,13 +14,11 @@ // Load app config onMount(async () => { - await routeStore.actions.fetchRoutes() - await screenStore.actions.fetchScreens() + await initialise() loaded = true }) {#if loaded && $screenStore.activeLayout} - {/if} diff --git a/packages/client/src/components/Router.svelte b/packages/client/src/components/Router.svelte index 5684b189eb..3c2d71c422 100644 --- a/packages/client/src/components/Router.svelte +++ b/packages/client/src/components/Router.svelte @@ -7,7 +7,15 @@ const { styleable } = getContext("sdk") const component = getContext("component") - $: routerConfig = getRouterConfig($routeStore.routes) + // Only wrap this as an array to take advantage of svelte keying, + // to ensure the svelte-spa-router is fully remounted when route config + // changes + $: configs = [ + { + routes: getRouterConfig($routeStore.routes), + id: $routeStore.routeSessionId, + }, + ] const getRouterConfig = routes => { let config = {} @@ -25,11 +33,11 @@ } -{#if routerConfig} +{#each configs as config (config.id)}
- +
-{/if} +{/each}