mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 12:50:01 +00:00
web: fix auto navigation on scale change for about & settings pages
This commit is contained in:
parent
140683a679
commit
520725462a
7 changed files with 19 additions and 33 deletions
|
@ -1,6 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { t } from "$lib/i18n/translations";
|
import { t } from "$lib/i18n/translations";
|
||||||
import { defaultSettingsPage } from "$lib/subnav";
|
import { defaultNavPage } from "$lib/subnav";
|
||||||
|
|
||||||
import CobaltLogo from "$components/sidebar/CobaltLogo.svelte";
|
import CobaltLogo from "$components/sidebar/CobaltLogo.svelte";
|
||||||
import SidebarTab from "$components/sidebar/SidebarTab.svelte";
|
import SidebarTab from "$components/sidebar/SidebarTab.svelte";
|
||||||
|
@ -15,9 +15,9 @@
|
||||||
import IconInfoCircle from "@tabler/icons-svelte/IconInfoCircle.svelte";
|
import IconInfoCircle from "@tabler/icons-svelte/IconInfoCircle.svelte";
|
||||||
|
|
||||||
let screenWidth: number;
|
let screenWidth: number;
|
||||||
let settingsLink = defaultSettingsPage();
|
let settingsLink = defaultNavPage("settings");
|
||||||
|
|
||||||
$: screenWidth, settingsLink = defaultSettingsPage();
|
$: screenWidth, settingsLink = defaultNavPage("settings");
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:window bind:innerWidth={screenWidth} />
|
<svelte:window bind:innerWidth={screenWidth} />
|
||||||
|
|
|
@ -2,14 +2,14 @@
|
||||||
import { page } from "$app/stores";
|
import { page } from "$app/stores";
|
||||||
import { goto } from "$app/navigation";
|
import { goto } from "$app/navigation";
|
||||||
import { browser } from "$app/environment";
|
import { browser } from "$app/environment";
|
||||||
|
import { defaultNavPage } from "$lib/subnav";
|
||||||
|
|
||||||
import { t } from "$lib/i18n/translations";
|
import { t } from "$lib/i18n/translations";
|
||||||
|
|
||||||
import IconArrowLeft from "@tabler/icons-svelte/IconArrowLeft.svelte";
|
import IconArrowLeft from "@tabler/icons-svelte/IconArrowLeft.svelte";
|
||||||
|
|
||||||
export let pageName: string;
|
export let pageName: "settings" | "about";
|
||||||
export let homeNavPath: string;
|
export let homeNavPath: string;
|
||||||
export let homeDesktopPath: string;
|
|
||||||
export let homeTitle: string;
|
export let homeTitle: string;
|
||||||
export let pageSubtitle = "";
|
export let pageSubtitle = "";
|
||||||
export let contentPadding = false;
|
export let contentPadding = false;
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
$: isHome = $page.url.pathname === homeNavPath;
|
$: isHome = $page.url.pathname === homeNavPath;
|
||||||
$: {
|
$: {
|
||||||
if (browser && !isMobile && isHome) {
|
if (browser && !isMobile && isHome) {
|
||||||
goto(homeDesktopPath, { replaceState: true });
|
goto(defaultNavPage(pageName), { replaceState: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,26 +1,16 @@
|
||||||
import { browser } from "$app/environment";
|
import { browser } from "$app/environment";
|
||||||
|
|
||||||
const defaultSettingsPage = () => {
|
const defaultNavPage = (page: "settings" | "about") => {
|
||||||
if (browser) {
|
if (browser && window.innerWidth <= 750) {
|
||||||
if (window.innerWidth <= 750) {
|
return `/${page}`;
|
||||||
return "/settings";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "/settings/appearance";
|
switch (page) {
|
||||||
}
|
case "settings":
|
||||||
|
return "/settings/appearance";
|
||||||
const defaultAboutPage = () => {
|
case "about":
|
||||||
if (browser) {
|
return "/about/general";
|
||||||
if (window.innerWidth <= 750) {
|
|
||||||
return "/about";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "/about/general";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export { defaultNavPage };
|
||||||
defaultSettingsPage,
|
|
||||||
defaultAboutPage
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import { page } from "$app/stores";
|
import { page } from "$app/stores";
|
||||||
import { goto } from "$app/navigation";
|
import { goto } from "$app/navigation";
|
||||||
import { defaultSettingsPage } from "$lib/subnav";
|
import { defaultNavPage } from "$lib/subnav";
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if ($page.error?.message === "Not Found") {
|
if ($page.error?.message === "Not Found") {
|
||||||
if ($page.url.pathname.startsWith("/settings")) {
|
if ($page.url.pathname.startsWith("/settings")) {
|
||||||
goto(defaultSettingsPage(), { replaceState: true });
|
goto(defaultNavPage("settings"), { replaceState: true });
|
||||||
} else {
|
} else {
|
||||||
goto("/", { replaceState: true });
|
goto("/", { replaceState: true });
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { t } from "$lib/i18n/translations";
|
import { t } from "$lib/i18n/translations";
|
||||||
import { defaultAboutPage } from "$lib/subnav";
|
|
||||||
|
|
||||||
import PageNav from "$components/subnav/PageNav.svelte";
|
import PageNav from "$components/subnav/PageNav.svelte";
|
||||||
|
|
||||||
|
@ -20,7 +19,6 @@
|
||||||
|
|
||||||
<PageNav
|
<PageNav
|
||||||
pageName="about"
|
pageName="about"
|
||||||
homeDesktopPath={defaultAboutPage()}
|
|
||||||
homeNavPath="/about"
|
homeNavPath="/about"
|
||||||
homeTitle={$t("tabs.about")}
|
homeTitle={$t("tabs.about")}
|
||||||
contentPadding
|
contentPadding
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
import { version } from "$lib/version";
|
import { version } from "$lib/version";
|
||||||
import { t } from "$lib/i18n/translations";
|
import { t } from "$lib/i18n/translations";
|
||||||
import { defaultSettingsPage } from "$lib/subnav";
|
|
||||||
|
|
||||||
import PageNav from "$components/subnav/PageNav.svelte";
|
import PageNav from "$components/subnav/PageNav.svelte";
|
||||||
|
|
||||||
|
@ -27,7 +26,6 @@
|
||||||
<PageNav
|
<PageNav
|
||||||
pageName="settings"
|
pageName="settings"
|
||||||
pageSubtitle={versionText}
|
pageSubtitle={versionText}
|
||||||
homeDesktopPath={defaultSettingsPage()}
|
|
||||||
homeNavPath="/settings"
|
homeNavPath="/settings"
|
||||||
homeTitle={$t("tabs.settings")}
|
homeTitle={$t("tabs.settings")}
|
||||||
>
|
>
|
||||||
|
|
|
@ -4,12 +4,12 @@
|
||||||
|
|
||||||
import { version } from "$lib/version";
|
import { version } from "$lib/version";
|
||||||
import { device, app } from "$lib/device";
|
import { device, app } from "$lib/device";
|
||||||
import { defaultSettingsPage } from "$lib/subnav";
|
import { defaultNavPage } from "$lib/subnav";
|
||||||
import settings, { storedSettings } from "$lib/state/settings";
|
import settings, { storedSettings } from "$lib/state/settings";
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (!$settings.advanced.debug) {
|
if (!$settings.advanced.debug) {
|
||||||
goto(defaultSettingsPage(), { replaceState: true });
|
goto(defaultNavPage("settings"), { replaceState: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue