Skip to content

Conversation

@ishanBahuguna
Copy link
Contributor

@ishanBahuguna ishanBahuguna commented Sep 8, 2025

Proposed change

Move the Sign in button from the Header to the side navigation on small devices.
It should have the same styling as the other buttons and appear at the top.

Resolves #2226

  • Added a new custom hook useIsMobile to detect window size

  • Updated Header to conditionally render the UserMenu component based on the useIsMobile hook.

    • On desktop screens: UserMenu appears in the header bar.
    • On mobile screens: UserMenu is moved into the side navigation.

    Working:

Screencast.from.08-09-25.11.35.57.AM.IST.webm

Checklist

  • I've read and followed the contributing guidelines.
  • I've run make check-test locally; all checks and tests passed.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 8, 2025

Summary by CodeRabbit

  • New Features
    • Improved responsive header: the user menu now appears in the mobile drawer on small screens and remains in the header on desktop, making navigation clearer and reducing clutter.
  • Refactor
    • Introduced mobile viewport detection to conditionally render UI elements, ensuring consistent behavior across devices and smoother updates when resizing.
    • Enhanced cross-browser reliability of responsive behavior with graceful fallbacks, providing a more stable experience on mobile and desktop.

Walkthrough

Adds a new useIsMobile hook and updates Header.tsx to conditionally render UserMenu in the desktop header when not mobile and inside the mobile drawer when mobile. No public API changes.

Changes

Cohort / File(s) Summary of changes
Header — conditional UserMenu
frontend/src/components/Header.tsx
Import and call useIsMobile; render UserMenu in desktop header only when not mobile and render it inside the mobile drawer when mobile.
Viewport detection hook
frontend/src/hooks/useIsMobile.ts
Add useIsMobile() hook that returns a boolean based on a (max-width: desktopViewMinWidth - 1px) media query; sets initial state from current media query and subscribes to change events with addEventListener/addListener fallbacks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • arkid15r
  • kasya

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
		  - name: "Undocumented Breaking Changes"
			  mode: "warning"
			  instructions: |
				  Flag potential breaking changes that are not documented:
				  1. Identify changes to public APIs/exports, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints (including removed/renamed items and changes to types, required params, return values, defaults, or behavior).
				  2. Ignore purely internal/private changes (e.g., code not exported from package entry points or marked internal).
				  3. Verify documentation exists: a "Breaking Change" section in the PR description and updates to CHANGELOG.md.

Please share your feedback with us on this Discord post.


📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb32f88 and 67090ef.

📒 Files selected for processing (1)
  • frontend/src/hooks/useIsMobile.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/hooks/useIsMobile.ts

Pre-merge checks (4 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly summarizes the main change by stating that the sign-in button is moved from the header to the side nav on small devices, which aligns precisely with the changes in the diff.
Linked Issues Check ✅ Passed The implementation moves the UserMenu component into the side navigation on mobile, maintains its styling by reusing the existing component, and positions it within the mobile drawer, fulfilling the linked issue requirements.
Out of Scope Changes Check ✅ Passed All changes are directly related to mobile detection and repositioning of the UserMenu; no unrelated files or features were modified.
Description Check ✅ Passed The description clearly explains the change of moving the Sign in button from the header to the side navigation on small devices, references the new useIsMobile hook, and outlines how the Header component’s rendering is conditionally updated, matching the actual implementation in the changeset.
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
frontend/src/hooks/useIsMobile.ts (1)

3-4: Consider generalizing to a reusable useMediaQuery.

Optional: export useMediaQuery(query: string) and derive useIsMobile from it for other breakpoints later.

frontend/src/components/Header.tsx (3)

23-23: Ensure breakpoint alignment with useIsMobile.

With the hook fix using desktopViewMinWidth - 1, this call is fine. If you prefer not to couple the hook to utils/constants, change the hook to accept a param and call it as below.

-const isMobile = useIsMobile()
+const isMobile = useIsMobile(desktopViewMinWidth)

133-133: Avoid initial mobile flicker by also hiding via CSS at small widths.

Before the hook updates on mount, the header UserMenu can briefly render on mobile. Wrap with a responsive utility to keep it hidden on <md regardless of JS timing.

-          {!isMobile && <UserMenu isGitHubAuthEnabled={isGitHubAuthEnabled} />}
+          {!isMobile && (
+            <div className="hidden md:block">
+              <UserMenu isGitHubAuthEnabled={isGitHubAuthEnabled} />
+            </div>
+          )}

229-229: Verify styling parity for “Sign in” with side-nav buttons.

UserMenu’s unauthenticated button styling differs from NavButton. If strict visual parity is required per #2226, consider a prop/variant on UserMenu that renders a NavButton-styled “Sign in” (icon + label), or a small SignInNavButton component used here.

If helpful, I can draft a SignInNavButton that delegates to signIn('github', ...) while matching NavButton styles.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b1c5f1 and 4ff1ef3.

📒 Files selected for processing (2)
  • frontend/src/components/Header.tsx (4 hunks)
  • frontend/src/hooks/useIsMobile.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
frontend/src/components/Header.tsx (2)
frontend/src/hooks/useIsMobile.ts (1)
  • useIsMobile (3-18)
frontend/src/components/UserMenu.tsx (1)
  • UserMenu (13-119)
🔇 Additional comments (1)
frontend/src/components/Header.tsx (1)

9-9: Import looks good.

No issues with the alias usage.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
frontend/src/hooks/useIsMobile.ts (1)

7-10: Use a shared breakpoint constant instead of hard-coding 767px (prevents drift).

Tie this to the app’s desktop min width so Tailwind/config changes don’t silently break the switch.

-import { useEffect, useState } from 'react'
+import { useEffect, useState } from 'react'
+import { desktopViewMinWidth } from 'utils/constants'
@@
-    const mediaQuery = window.matchMedia('(max-width: 767px)')
+    const mediaQuery = window.matchMedia(`(max-width:${desktopViewMinWidth - 1}px)`)
🧹 Nitpick comments (3)
frontend/src/hooks/useIsMobile.ts (3)

9-16: Guard for environments without matchMedia (JSDOM/old browsers).

Avoid runtime errors in tests or non-browser contexts.

-    const mediaQuery = window.matchMedia('(max-width: 767px)')
+    if (typeof window.matchMedia !== 'function') {
+      // No-op: keep default false and exit effect
+      return
+    }
+    const mediaQuery = window.matchMedia('(max-width: 767px)')
@@
-    updateMatch(mediaQuery)
+    updateMatch(mediaQuery)

17-24: Prefer explicit typeof checks for listener APIs and handle “neither” case.

Slightly safer narrowing and avoids truthy checks on non-functions.

-    if (mediaQuery.addEventListener) {
+    if (typeof mediaQuery.addEventListener === 'function') {
       mediaQuery.addEventListener('change', updateMatch)
-      return () => mediaQuery.removeEventListener('change', updateMatch)
-    } else {
+      return () => mediaQuery.removeEventListener('change', updateMatch)
+    } else if (typeof mediaQuery.addListener === 'function') {
       // Safari browser < 14 fallback
-      mediaQuery.addListener(updateMatch)
-      return () => mediaQuery.removeListener(updateMatch)
+      mediaQuery.addListener(updateMatch)
+      return () => mediaQuery.removeListener(updateMatch)
+    } else {
+      // Nothing to clean up
+      return
     }

3-5: Optional: reduce layout shift with useSyncExternalStore.

Not required, but a useSyncExternalStore-based hook can minimize initial flicker on mobile by reading the current snapshot before paint.

If you want, I can provide a useMediaQuery(query) helper built on useSyncExternalStore and refactor this hook to use it.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ff1ef3 and 31095e1.

📒 Files selected for processing (1)
  • frontend/src/hooks/useIsMobile.ts (1 hunks)
🔇 Additional comments (1)
frontend/src/hooks/useIsMobile.ts (1)

11-16: Handler design is solid (works for both modern and legacy MQL).

Good call unifying the event and list cases via e.matches and syncing initial state immediately.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 9, 2025

Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

I can see some things we'd want to improve further, but that will be a separate issue 👌🏼

@kasya kasya added this pull request to the merge queue Sep 9, 2025
Merged via the queue into OWASP:main with commit f038c59 Sep 9, 2025
25 checks passed
@ishanBahuguna ishanBahuguna deleted the feature/move-signin-button-to-side-nav branch September 9, 2025 16:25
arkid15r pushed a commit that referenced this pull request Sep 10, 2025
…2231)

* moved the signin button to nav bar on small screens and added useIsMobile custom hook

* moved the signin button to nav bar on small screens and added useIsMobile custom hook

* fixed useIsMobile hook to support all browsers

* made the useIsMobile hook compatible with old browsers

* fixed error

---------

Co-authored-by: Kate Golovanova <kate@kgthreads.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move Sign in button to side nav

2 participants