web: fix auto navigation on scale change for about & settings pages

This commit is contained in:
wukko 2024-09-04 21:20:56 +06:00
parent 140683a679
commit 520725462a
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2
7 changed files with 19 additions and 33 deletions

View file

@ -1,6 +1,6 @@
<script lang="ts">
import { t } from "$lib/i18n/translations";
import { defaultSettingsPage } from "$lib/subnav";
import { defaultNavPage } from "$lib/subnav";
import CobaltLogo from "$components/sidebar/CobaltLogo.svelte";
import SidebarTab from "$components/sidebar/SidebarTab.svelte";
@ -15,9 +15,9 @@
import IconInfoCircle from "@tabler/icons-svelte/IconInfoCircle.svelte";
let screenWidth: number;
let settingsLink = defaultSettingsPage();
let settingsLink = defaultNavPage("settings");
$: screenWidth, settingsLink = defaultSettingsPage();
$: screenWidth, settingsLink = defaultNavPage("settings");
</script>
<svelte:window bind:innerWidth={screenWidth} />

View file

@ -2,14 +2,14 @@
import { page } from "$app/stores";
import { goto } from "$app/navigation";
import { browser } from "$app/environment";
import { defaultNavPage } from "$lib/subnav";
import { t } from "$lib/i18n/translations";
import IconArrowLeft from "@tabler/icons-svelte/IconArrowLeft.svelte";
export let pageName: string;
export let pageName: "settings" | "about";
export let homeNavPath: string;
export let homeDesktopPath: string;
export let homeTitle: string;
export let pageSubtitle = "";
export let contentPadding = false;
@ -27,7 +27,7 @@
$: isHome = $page.url.pathname === homeNavPath;
$: {
if (browser && !isMobile && isHome) {
goto(homeDesktopPath, { replaceState: true });
goto(defaultNavPage(pageName), { replaceState: true });
}
}
</script>

View file

@ -1,26 +1,16 @@
import { browser } from "$app/environment";
const defaultSettingsPage = () => {
if (browser) {
if (window.innerWidth <= 750) {
return "/settings";
}
const defaultNavPage = (page: "settings" | "about") => {
if (browser && window.innerWidth <= 750) {
return `/${page}`;
}
switch (page) {
case "settings":
return "/settings/appearance";
}
const defaultAboutPage = () => {
if (browser) {
if (window.innerWidth <= 750) {
return "/about";
}
}
case "about":
return "/about/general";
}
}
export {
defaultSettingsPage,
defaultAboutPage
}
export { defaultNavPage };

View file

@ -2,12 +2,12 @@
import { onMount } from "svelte";
import { page } from "$app/stores";
import { goto } from "$app/navigation";
import { defaultSettingsPage } from "$lib/subnav";
import { defaultNavPage } from "$lib/subnav";
onMount(() => {
if ($page.error?.message === "Not Found") {
if ($page.url.pathname.startsWith("/settings")) {
goto(defaultSettingsPage(), { replaceState: true });
goto(defaultNavPage("settings"), { replaceState: true });
} else {
goto("/", { replaceState: true });
}

View file

@ -1,6 +1,5 @@
<script lang="ts">
import { t } from "$lib/i18n/translations";
import { defaultAboutPage } from "$lib/subnav";
import PageNav from "$components/subnav/PageNav.svelte";
@ -20,7 +19,6 @@
<PageNav
pageName="about"
homeDesktopPath={defaultAboutPage()}
homeNavPath="/about"
homeTitle={$t("tabs.about")}
contentPadding

View file

@ -3,7 +3,6 @@
import { version } from "$lib/version";
import { t } from "$lib/i18n/translations";
import { defaultSettingsPage } from "$lib/subnav";
import PageNav from "$components/subnav/PageNav.svelte";
@ -27,7 +26,6 @@
<PageNav
pageName="settings"
pageSubtitle={versionText}
homeDesktopPath={defaultSettingsPage()}
homeNavPath="/settings"
homeTitle={$t("tabs.settings")}
>

View file

@ -4,12 +4,12 @@
import { version } from "$lib/version";
import { device, app } from "$lib/device";
import { defaultSettingsPage } from "$lib/subnav";
import { defaultNavPage } from "$lib/subnav";
import settings, { storedSettings } from "$lib/state/settings";
onMount(() => {
if (!$settings.advanced.debug) {
goto(defaultSettingsPage(), { replaceState: true });
goto(defaultNavPage("settings"), { replaceState: true });
}
});
</script>