Fix model selector on mobile

This commit is contained in:
anonymous
2026-01-11 20:15:23 -08:00
committed by Shirone
parent acce06b304
commit d2c7a9e05d
3 changed files with 538 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
import { useState, useEffect } from 'react';
/**
* Hook to detect if a media query matches
* @param query - The media query string (e.g., '(max-width: 768px)')
* @returns boolean indicating if the media query matches
*/
export function useMediaQuery(query: string): boolean {
const [matches, setMatches] = useState(() => {
if (typeof window === 'undefined') return false;
return window.matchMedia(query).matches;
});
useEffect(() => {
if (typeof window === 'undefined') return;
const mediaQuery = window.matchMedia(query);
const handleChange = (e: MediaQueryListEvent) => {
setMatches(e.matches);
};
// Set initial value
setMatches(mediaQuery.matches);
// Listen for changes
mediaQuery.addEventListener('change', handleChange);
return () => {
mediaQuery.removeEventListener('change', handleChange);
};
}, [query]);
return matches;
}
/**
* Hook to detect if the device is mobile (screen width <= 768px)
* @returns boolean indicating if the device is mobile
*/
export function useIsMobile(): boolean {
return useMediaQuery('(max-width: 768px)');
}
/**
* Hook to detect if the device is tablet or smaller (screen width <= 1024px)
* @returns boolean indicating if the device is tablet or smaller
*/
export function useIsTablet(): boolean {
return useMediaQuery('(max-width: 1024px)');
}