Skip to content

best way to save what you love

web/settings: redirect invalid settings paths to default settings page

dumbmoron16c76e7e9216
diff --git a/web/src/lib/settings/defaults.ts b/web/src/lib/settings/defaults.ts
index 362696ff..33d35603 100644
--- a/web/src/lib/settings/defaults.ts
+++ b/web/src/lib/settings/defaults.ts
@@ -1,3 +1,4 @@
+import { browser } from "$app/environment";
import { defaultLocale } from "$lib/i18n/translations";
import type { CobaltSettings } from "$lib/types/settings";
@@ -35,4 +36,15 @@ const defaultSettings: CobaltSettings = {
},
}
+const defaultSettingsPage = () => {
+ if (browser) {
+ if (window.innerWidth <= 750) {
+ return "/settings";
+ }
+ }
+
+ return "/settings/general/appearance";
+}
+
export default defaultSettings;
+export { defaultSettingsPage };
\ No newline at end of file
diff --git a/web/src/routes/+error.svelte b/web/src/routes/+error.svelte
new file mode 100644
index 00000000..ba0b6166
--- /dev/null
+++ b/web/src/routes/+error.svelte
@@ -0,0 +1,17 @@
+<script lang="ts">
+ import { goto } from '$app/navigation';
+ import { page } from '$app/stores';
+ import { defaultSettingsPage } from '$lib/settings/defaults';
+
+ $: {
+ if (
+ $page.error?.message === 'Not Found'
+ && $page.url.pathname.startsWith('/settings')
+ ) {
+ goto(defaultSettingsPage(), { replaceState: true });
+ }
+ }
+</script>
+
+<!-- TODO: nicer errors -->
+<h1>{$page.status}: {$page.error?.message}</h1>
\ No newline at end of file