test: restore project verification suite

This commit is contained in:
boos
2026-06-06 03:35:29 +08:00
parent e4630c4cb6
commit fae0f607aa
12 changed files with 55 additions and 46 deletions
+7 -6
View File
@@ -8,11 +8,12 @@ export function useIsMobile(breakpoint = MOBILE_BREAKPOINT) {
useEffect(() => {
if (typeof window === 'undefined') return;
const targetWindow = window;
const query = breakpoint === MOBILE_BREAKPOINT
? MOBILE_MEDIA_QUERY
: `(max-width: ${breakpoint}px)`;
const media = typeof window.matchMedia === 'function' ? window.matchMedia(query) : null;
const update = () => setIsMobile(media ? media.matches : window.innerWidth <= breakpoint);
const media = typeof targetWindow.matchMedia === 'function' ? targetWindow.matchMedia(query) : null;
const update = () => setIsMobile(media ? media.matches : targetWindow.innerWidth <= breakpoint);
update();
if (media && typeof media.addEventListener === 'function') {
@@ -24,14 +25,14 @@ export function useIsMobile(breakpoint = MOBILE_BREAKPOINT) {
};
}
const addResizeListener = typeof window.addEventListener === 'function';
const removeResizeListener = typeof window.removeEventListener === 'function';
const addResizeListener = typeof targetWindow.addEventListener === 'function';
const removeResizeListener = typeof targetWindow.removeEventListener === 'function';
if (!addResizeListener) return;
window.addEventListener('resize', update);
targetWindow.addEventListener('resize', update);
return () => {
if (removeResizeListener) {
window.removeEventListener('resize', update);
targetWindow.removeEventListener('resize', update);
}
};
}, [breakpoint]);