summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ui/routes/(app)/+layout.svelte33
-rw-r--r--ui/routes/+layout.svelte27
2 files changed, 30 insertions, 30 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} />
diff --git a/ui/routes/+layout.svelte b/ui/routes/+layout.svelte
index 18c0541..5bccd2f 100644
--- a/ui/routes/+layout.svelte
+++ b/ui/routes/+layout.svelte
@@ -1,14 +1,11 @@
<script>
import { setContext } from 'svelte';
- import { browser } from '$app/environment';
- import { goto, onNavigate, afterNavigate } from '$app/navigation';
+ import { onNavigate } from '$app/navigation';
import { page } from '$app/stores';
import '../app.css';
import logo from '$lib/assets/logo.png';
- import { STORE_KEY_LAST_ACTIVE } from '$lib/constants';
import { currentUser } from '$lib/store';
- let activeChannel = $derived($page.params.channel);
let pageContext = $state({
showMenu: false
@@ -20,28 +17,6 @@
pageContext.showMenu = !pageContext.showMenu;
}
- 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();
- if (!activeChannel && lastActiveChannel) {
- goto(`/ch/${lastActiveChannel}`);
- } else {
- setLastActiveChannel(activeChannel || null);
- }
- });
-
onNavigate(() => {
pageContext.showMenu = false;
});