diff options
| author | Kit La Touche <kit@transneptune.net> | 2025-02-21 23:19:30 -0500 |
|---|---|---|
| committer | Kit La Touche <kit@transneptune.net> | 2025-02-21 23:19:30 -0500 |
| commit | e561ff74b81209b8e0f0c7cc63861a2ef70d19bf (patch) | |
| tree | 54ca1c1d718f54c9d9725dd050ae540b181870e2 /ui/routes/(app) | |
| parent | 9d1dbac74866a6175c65a25bbd8a3ccbe8cf87e4 (diff) | |
Only redirect to last active channel off of /
Diffstat (limited to 'ui/routes/(app)')
| -rw-r--r-- | ui/routes/(app)/+layout.svelte | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/ui/routes/(app)/+layout.svelte b/ui/routes/(app)/+layout.svelte index 888a185..20620d4 100644 --- a/ui/routes/(app)/+layout.svelte +++ b/ui/routes/(app)/+layout.svelte @@ -1,13 +1,15 @@ <script> - import { page } from '$app/state'; - import { goto } from '$app/navigation'; - import { browser } from '$app/environment'; import { getContext, onDestroy, onMount } from 'svelte'; + + import { browser } from '$app/environment'; + import { goto, afterNavigate } from '$app/navigation'; + import { page } from '$app/state'; + import TinyGesture from 'tinygesture'; import { boot, subscribeToEvents } from '$lib/apiServer'; + import { STORE_KEY_LAST_ACTIVE } from '$lib/constants'; import { channelsList, channelsMetaList, currentUser, logins, messages, onEvent } from '$lib/store'; - import ChannelList from '$lib/components/ChannelList.svelte'; import CreateChannelForm from '$lib/components/CreateChannelForm.svelte'; @@ -112,6 +114,29 @@ event.returnValue = ''; return ''; } + + function getLastActiveChannel() { + return ( + browser && JSON.parse(localStorage.getItem(STORE_KEY_LAST_ACTIVE)) + ); + } + + function setLastActiveChannel(channelId) { + browser && localStorage.setItem( + STORE_KEY_LAST_ACTIVE, + JSON.stringify(channelId) + ); + } + + afterNavigate(() => { + const lastActiveChannel = getLastActiveChannel(); + const inRoot = page.url.pathname === '/'; + if (inRoot && lastActiveChannel) { + goto(`/ch/${lastActiveChannel}`); + } else if (channel) { + setLastActiveChannel(channel || null); + } + }); </script> <svelte:window {onbeforeunload} /> |
