feat(hooks): add SSR-safe useMediaQuery + breakpoint helpers (#437)#455
Open
almuslavish wants to merge 1 commit into
Open
feat(hooks): add SSR-safe useMediaQuery + breakpoint helpers (#437)#455almuslavish wants to merge 1 commit into
almuslavish wants to merge 1 commit into
Conversation
Centralizes matchMedia subscriptions and uses it to adapt the Trust Score activity panel at the mobile breakpoint. - useMediaQuery(query): SSR-safe, listener-cleaned-up boolean hook - useIsMobile(): shorthand for (max-width: 767px) threshold - TrustScore: switch activity card heading between 'Recent Activity' (mobile) and 'Recent Activity Timeline' (desktop) - Vitest tests: no-window guard, initial value, change events, cleanup, query re-subscription, useIsMobile query string - HOOKS.md: document useMediaQuery and useIsMobile Closes CredenceOrg#437
|
@almuslavish Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #437
Summary
Implements #437.
Adds a typed, SSR-safe
useMediaQueryhook that centralizesmatchMediasubscriptions, removes the need for scattered inline calls, and enables JS-driven responsive component behavior alongside the existing CSS reflow.Changes
src/hooks/useMediaQuery.ts(new)useMediaQuery(query: string): boolean— subscribes to any CSS media query, cleans up the listener on unmount, returnsfalsewhenwindow/matchMediais unavailable (SSR-safe).useIsMobile(): boolean— named breakpoint helper at the repo-documented 768 px threshold ((max-width: 767px)).addEventListener/removeEventListenerpattern fromSettingsContext.useStateinitializer reads the initial match synchronously — no flash of wrong state.src/pages/TrustScore.tsxuseIsMobile.Recent Activity, desktop →Recent Activity Timeline.src/hooks/useMediaQuery.test.ts(new)Vitest tests covering:
false, no crash)false/trueuseIsMobilebreakpoint value and query string assertiondocs/HOOKS.mduseMediaQuery/useIsMobileto the Contents list.useReducedMotion.Acceptance criteria
useMediaQuery+ breakpoint helpers implemented