diff options
| author | Fuwn <[email protected]> | 2026-02-09 23:48:27 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-09 23:48:27 -0800 |
| commit | d0d49d9b759f841c0a05b2410efbd26957a813dc (patch) | |
| tree | 6c72bd6a27e13b6cadb2d1797afedc172ffc32e7 /apps/web/lib/hooks | |
| parent | fix: P0 correctness and security fixes (diff) | |
| download | asa.news-d0d49d9b759f841c0a05b2410efbd26957a813dc.tar.xz asa.news-d0d49d9b759f841c0a05b2410efbd26957a813dc.zip | |
fix: P0 correctness/security fixes and P1 lint error resolution
P0: add missing 'developer' case to check_custom_feed_limit trigger,
scope user_entry_states join to authenticated user in API v1 entries,
replace in-memory rate limiting with Supabase-backed check_rate_limit RPC.
P1: fix all 9 ESLint errors — useSyncExternalStore for useIsMobile,
restructure WebhookSection to avoid set-state-in-effect, move ref
mutations into useEffect, replace <a> with <Link> on shared page,
ignore generated public/sw.js in eslint config.
Diffstat (limited to 'apps/web/lib/hooks')
| -rw-r--r-- | apps/web/lib/hooks/use-is-mobile.ts | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/apps/web/lib/hooks/use-is-mobile.ts b/apps/web/lib/hooks/use-is-mobile.ts index a56e36c..0074ef5 100644 --- a/apps/web/lib/hooks/use-is-mobile.ts +++ b/apps/web/lib/hooks/use-is-mobile.ts @@ -1,26 +1,24 @@ "use client" -import { useState, useEffect } from "react" +import { useSyncExternalStore } from "react" const MOBILE_BREAKPOINT = 768 +const MEDIA_QUERY = `(max-width: ${MOBILE_BREAKPOINT - 1}px)` -export function useIsMobile(): boolean { - const [isMobile, setIsMobile] = useState(false) - - useEffect(() => { - const mediaQuery = window.matchMedia( - `(max-width: ${MOBILE_BREAKPOINT - 1}px)` - ) - - setIsMobile(mediaQuery.matches) +function subscribe(callback: () => void) { + const mediaQueryList = window.matchMedia(MEDIA_QUERY) + mediaQueryList.addEventListener("change", callback) + return () => mediaQueryList.removeEventListener("change", callback) +} - function handleChange(event: MediaQueryListEvent) { - setIsMobile(event.matches) - } +function getSnapshot() { + return window.matchMedia(MEDIA_QUERY).matches +} - mediaQuery.addEventListener("change", handleChange) - return () => mediaQuery.removeEventListener("change", handleChange) - }, []) +function getServerSnapshot() { + return false +} - return isMobile +export function useIsMobile(): boolean { + return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) } |