From 02f0815751d3ef65bc9206a87aa1d19795b214d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Mon, 29 Nov 2021 23:52:40 +0100 Subject: [PATCH] Store previous page for photo Viewer close button --- src/routes/[country]/[location]/[photo].svelte | 3 ++- src/routes/__layout.svelte | 10 +++++++++- src/utils/stores/index.ts | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/routes/[country]/[location]/[photo].svelte b/src/routes/[country]/[location]/[photo].svelte index a914d1a..6181a56 100644 --- a/src/routes/[country]/[location]/[photo].svelte +++ b/src/routes/[country]/[location]/[photo].svelte @@ -5,6 +5,7 @@ import { scale } from 'svelte/transition' import { quartOut } from 'svelte/easing' import { getAssetUrlKey } from '$utils/helpers' + import { previousPage } from '$utils/stores' import { throttle } from '$utils/functions' import { swipe } from '$utils/interactions/swipe' import dayjs from 'dayjs' @@ -220,7 +221,7 @@ diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte index bf206c4..630e5f1 100644 --- a/src/routes/__layout.svelte +++ b/src/routes/__layout.svelte @@ -2,7 +2,7 @@ import '../style/style.scss' import { navigating, page } from '$app/stores' import { onMount, setContext } from 'svelte' - import { pageLoading } from '$utils/stores' + import { pageLoading, previousPage } from '$utils/stores' import { scrollToTop } from '$utils/functions' import { DURATION } from '$utils/contants' import '$utils/polyfills' @@ -24,6 +24,14 @@ /** * On page change */ + // Store previous page (for photo Viewer close button) + let previous = '' + page.subscribe(value => { + $previousPage = previous + previous = value.path + }) + + // Define page loading from navigating store navigating.subscribe((store: any) => { if (store) { $pageLoading = true diff --git a/src/utils/stores/index.ts b/src/utils/stores/index.ts index e665323..223e573 100644 --- a/src/utils/stores/index.ts +++ b/src/utils/stores/index.ts @@ -1,3 +1,4 @@ import { writable } from 'svelte/store' -export const pageLoading = writable(false) \ No newline at end of file +export const pageLoading = writable(false) +export const previousPage = writable('') \ No newline at end of file