Update listener

This commit is contained in:
ernstmul
2025-01-21 13:28:50 +01:00
parent e4deccc836
commit 3abffc9d91
2 changed files with 5 additions and 20 deletions
+1 -3
View File
@@ -133,9 +133,7 @@
};
function updateViewport() {
if (window) {
isSmallViewport = window.matchMedia('(max-width: 768px)').matches;
}
isSmallViewport = window.matchMedia('(max-width: 768px)').matches;
}
</script>
+4 -17
View File
@@ -47,23 +47,9 @@
showAccountMenu: boolean;
};
onMount(() => {
if (window) {
const mediaQuery = window.matchMedia('(max-width: 768px)');
const updateViewport = () => (isSmallViewport = mediaQuery.matches);
// Initial check
updateViewport();
// Listen for changes
mediaQuery.addEventListener('change', updateViewport);
return () => {
// Cleanup listener
mediaQuery.removeEventListener('change', updateViewport);
};
}
});
function updateViewport() {
isSmallViewport = window.matchMedia('(max-width: 768px)').matches;
}
function updateTheme(theme: 'light' | 'dark' | 'system') {
const themeInUse =
@@ -95,6 +81,7 @@
export let showAccountMenu = false;
</script>
<svelte:window on:resize={updateViewport} />
<Navbar.Base {...$$props}>
<div slot="left" class="left">
<div class="only-mobile">