fix: navbar active state tracking and mobile menu behavior#44
fix: navbar active state tracking and mobile menu behavior#44rohans02 wants to merge 2 commits intoDjedAlliance:mainfrom
Conversation
📝 WalkthroughWalkthroughThis pull request refactors the navbar active state tracking system from direct DOM manipulation to React state-driven approach. It introduces a centralized Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/App.tsx (1)
34-38: Avoid duplicating section metadata across App and Header.
sectionMaphere andnavItemsinHeader.tsxencode the same section ids independently. Consider a shared constant to prevent drift-related nav/observer mismatches.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/App.tsx` around lines 34 - 38, The section ids are duplicated between the sectionMap object in App (sectionMap) and navItems in Header (navItems); extract a shared constant (e.g., SECTION_IDS or NAV_SECTIONS) exported from a single module and import it into both App and Header so both use the same source of truth; update App to replace sectionMap with the imported constant (or a derived Record if mapping needed) and update Header to consume the same constant so navItems and any scroll/observer logic reference identical ids.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/App.tsx`:
- Around line 34-38: The section ids are duplicated between the sectionMap
object in App (sectionMap) and navItems in Header (navItems); extract a shared
constant (e.g., SECTION_IDS or NAV_SECTIONS) exported from a single module and
import it into both App and Header so both use the same source of truth; update
App to replace sectionMap with the imported constant (or a derived Record if
mapping needed) and update Header to consume the same constant so navItems and
any scroll/observer logic reference identical ids.
Addressed Issues:
Fixes #36
Changes:
src/App.tsxactiveSection/setActiveSectionReact state (useState<string>('home'))threshold: 0.8with{ threshold: 0.1, rootMargin: '-20% 0px -60% 0px' }— the Dapps section is taller than the viewport so 80% visibility was never achieved, meaning the observer never fired for itswitch/caseblock that useddocument.getElementsByClassName('active')[0].classList.remove('active')(unsafe DOM mutation, throws on fast scroll when no.activeelement exists) with a cleansetActiveSection(sectionId)calldocument.querySelectorcalls with asectionMap-driven loop; added proper observer cleanup in theuseEffectreturnsrc/components/pages/header/Header.tsxHeaderPropsinterface (activeSection: string,setActiveSection)Headernow receives active state as props instead of managing it via direct DOMclassName={`navbar-link${activeSection === item.section ? ' active' : ''}`}handleActive()now callssetIsOpen(false)— mobile menu closes on nav link tapnavItemsarray to eliminate repetitionScreenshots/Recordings:
Djed-navbar-resolve.mp4
Djed-mobile-navbar-resolve-1.mp4
Checklist
We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.
Summary by CodeRabbit
New Features