-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b5e991
commit f399ec7
Showing
1 changed file
with
11 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
import { writable } from 'svelte/store' | ||
import { BREAKPOINTS } from '$lib/constants' | ||
|
||
// Function to determine if the screen is mobile | ||
function _isMobile() { | ||
// Check if window is defined (runs only in browser environment) | ||
if (typeof window !== 'undefined') { | ||
return window.innerWidth < BREAKPOINTS.sm | ||
} | ||
// Return false if window is not defined (for server-side rendering) | ||
return false | ||
} | ||
import { writable, type Writable } from 'svelte/store' | ||
|
||
// Create a writable store with an initial value based on the current screen width | ||
export const isMobile = writable(_isMobile()) | ||
export const isMobile: Writable<boolean> = writable(_isMobile()) | ||
|
||
// Update the store value when the screen is resized | ||
if (typeof window !== 'undefined') { | ||
window.addEventListener('resize', () => { | ||
isMobile.set(_isMobile()) | ||
}) | ||
} | ||
|
||
function _isMobile(): boolean { | ||
// Check if window is defined (runs only in browser environment) | ||
if (typeof window !== 'undefined') { | ||
return window.innerWidth < BREAKPOINTS.sm | ||
} | ||
// Return false if window is not defined (for server-side rendering) | ||
return false | ||
} |