Fix window error for tests
This commit is contained in:
parent
6a71f80718
commit
2a7ba588e2
1 changed files with 12 additions and 3 deletions
|
@ -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 => {
|
||||||
|
// Check if window is available before setting the screen size
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
screenSize.set(window.innerWidth);
|
screenSize.set(window.innerWidth);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue