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

This commit is contained in:
dumbmoron 2024-07-04 22:18:02 +00:00
parent e98f76c8ee
commit 16c76e7e92
No known key found for this signature in database
2 changed files with 29 additions and 0 deletions

View file

@ -1,3 +1,4 @@
import { browser } from "$app/environment";
import { defaultLocale } from "$lib/i18n/translations"; import { defaultLocale } from "$lib/i18n/translations";
import type { CobaltSettings } from "$lib/types/settings"; 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 default defaultSettings;
export { defaultSettingsPage };

View file

@ -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>