Skip to content

Conversation

@Gunjan10-droid
Copy link

@Gunjan10-droid Gunjan10-droid commented Sep 13, 2025

This PR fixes the issue where clicking a navigation link (Home, Resources, etc.) while already on the same page did not reset the scroll position.

Fixes #86

Summary by CodeRabbit

  • New Features

    • Navigation update: Clicking the currently active menu item now smoothly scrolls to the top. Clicking a different route behaves as before.
  • Chores

    • Added a root project configuration to streamline running client and server together during development.
    • Introduced a client start script for launching the development server via npm.
    • Minor script formatting adjustments with no impact on behavior.

@vercel
Copy link

vercel bot commented Sep 13, 2025

@Gunjan10-droid is attempting to deploy a commit to the coderuzumaki's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Sep 13, 2025

Walkthrough

Adds a root package.json to orchestrate concurrent dev for server and client, introduces a client start script for Vite, and updates Header.jsx to scroll to top when clicking the active route while preserving normal navigation for route changes.

Changes

Cohort / File(s) Summary
Repo configuration
package.json
New root manifest with metadata and scripts: dev runs server and client concurrently via concurrently; adds server, client, and test scripts; sets repository/bugs/homepage fields; adds devDependency concurrently@^9.2.1.
Client scripts
client/package.json
Adds scripts.start = "vite"; ensures preview uses "vite preview". Enables npm start in client.
Header navigation behavior
client/src/components/Header.jsx
Imports useLocation; adds handleNavClick(to) to scroll to top when clicking the current route; attaches onClick to nav Links (/, /about, /interview/setup, /dashboard, /resources). No API/signature change.

Sequence Diagram(s)

sequenceDiagram
  actor User
  participant Header as Header.jsx
  participant Router as react-router-dom
  participant Window as window

  User->>Header: Click Nav Link (path: /resources)
  Header->>Router: Evaluate current location.pathname
  alt Same route clicked
    Header->>Window: window.scrollTo({ top: 0, behavior: "smooth" })
    note over Window: Scroll-to-top triggered
  else Different route
    Header->>Router: Navigate to target route
    Router-->>User: Route changes as usual
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I hop on links with nimble feet,
Click the same path—whoosh! top-seat.
Vite spins up, twin drums in sync,
Server and client—blink blink blink.
From burrow to navbar, I gleefully pop—
One more carrot-scroll straight to the top! 🥕⬆️

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning This PR also introduces unrelated configuration changes: a new root package.json and an added "start" script in client/package.json; those edits are not part of issue #86's scroll-to-top objective and therefore appear out of scope for this bugfix. Move the root package.json and client script changes into a separate PR or document why they must be included here; otherwise restrict this PR to the Header change to keep the scope minimal and reviewable.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix: scroll to top" is concise and accurately summarizes the primary change—restoring scroll-to-top behavior when navigation links are clicked—so it reflects the PR objective and is clear to reviewers.
Linked Issues Check ✅ Passed The changes to client/src/components/Header.jsx add useLocation and a handleNavClick wired to nav Links so clicking the active route triggers a smooth scroll-to-top, which directly implements the behavior described in issue #86 and the PR description references/fixes that issue.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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

@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

🧹 Nitpick comments (4)
client/package.json (1)

10-11: Clarify dev vs. start semantics (optional).

Having both dev and start run Vite dev is fine for the root concurrently flow, but it’s unconventional (start is often “production start” via vite preview). Two options:

  • Keep as-is and update root dev to call npm run dev --prefix client for consistency, or
  • Make start run vite preview (prod preview) and keep dev for development; then adjust the root dev script accordingly.

Example (if choosing option 2):

-    "preview": "vite preview",
-    "start": "vite"
+    "preview": "vite preview",
+    "start": "vite preview"

If you want to keep start for dev, consider updating the root script to call client dev for consistency.

client/src/components/Header.jsx (2)

59-64: Close menus and respect reduced motion when scrolling to top.

When clicking the active route in mobile, the drawer stays open. Also, prefer reduced motion if set. Update handleNavClick:

-  const handleNavClick = (to) => {
-    if (location.pathname === to) {
-      
-      window.scrollTo({ top: 0, behavior: "smooth" })
-    }
-  }
+  const handleNavClick = (to) => {
+    if (location.pathname === to) {
+      const prefersReducedMotion = window.matchMedia?.("(prefers-reduced-motion: reduce)")?.matches
+      window.scrollTo({ top: 0, behavior: prefersReducedMotion ? "auto" : "smooth" })
+    }
+    // Close any open UI chrome after a nav click
+    setIsMobileMenuOpen(false)
+    setIsDropdownOpen(false)
+  }

65-106: Good coverage of all primary links; consider NavLink for active styles (optional).

The onClick wiring meets the PR goal. If you later want automatic “active” styling and less manual path handling, swap Link for NavLink and derive isActive without passing strings into handleNavClick.

package.json (1)

2-5: Mark the root package as private to avoid accidental publish.

Add "private": true at the root. Also optional: add an engines field to document supported Node/npm versions.

 {
   "name": "prepedge-ai",
   "version": "1.0.0",
+  "private": true,
   "description": "<h1 align=\"center\"> PrepEdge AI </h1>\r <p align=\"center\"> An AI enabled smart Interview Preparation Platform </p>",
   "main": "index.js",

Also applies to: 16-26

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7ce03a2 and 28b2505.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • client/package.json (1 hunks)
  • client/src/components/Header.jsx (3 hunks)
  • package.json (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
client/src/components/Header.jsx (2)
client/src/components/ScrollToTop.jsx (2)
  • useLocation (5-5)
  • ScrollToTop (4-15)
client/src/App.jsx (1)
  • App (20-31)
🔇 Additional comments (2)
client/src/components/Header.jsx (1)

2-2: LGTM: useLocation import and usage.

Importing and wiring useLocation is correct for same-route detection.

Also applies to: 13-13

package.json (1)

6-9: No action required — client "start" and "dev" both run vite.
Root uses npm start --prefix client; client/package.json defines both "start" and "dev" as "vite" and server provides "dev" as "nodemon". Optional: switch root to npm run dev --prefix client for uniformity.

@vercel
Copy link

vercel bot commented Sep 20, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
prepedge_ai Ready Ready Preview Comment Sep 20, 2025 2:27pm

@CoderUzumaki
Copy link
Owner

Hey @Gunjan10-droid ,
Thank you for your interest, and I appreciate your contribution. However I must request for few changes before I can consider to merge this PR.

  1. 'Contact Us' links in footer and at the bottom in home page, redirects to contact us page, but they don't scroll to top. Since you are working on the same issue, you should see it.

  2. Ensure that your PR is correctly formatted according to the PR Template provided in our repository. Only the PRs following the templates are to be considered.

Thanks again for contributing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT]: Implement Scroll to Top on Navigation

2 participants