Fix window error for tests

This commit is contained in:
Djuri Baars 2024-06-09 00:34:10 +02:00
parent 6a71f80718
commit 2a7ba588e2

View File

@ -1,9 +1,18 @@
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
// Check if window is available
let initialWidth: number = 0;
if (typeof window !== 'undefined') {
initialWidth = window.innerWidth;
}
// Create a writable store to track screen size // Create a writable store to track screen size
export const screenSize = writable<number>(window.innerWidth); export const screenSize = writable<number>(initialWidth);
// Function to update the screen size // Function to update the screen size
export const updateScreenSize = () => { export const updateScreenSize = (): void => {
screenSize.set(window.innerWidth); // Check if window is available before setting the screen size
if (typeof window !== 'undefined') {
screenSize.set(window.innerWidth);
}
}; };