-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #201 : Active class for sidebar #221
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
"use client"; | ||
|
||
import { Fragment } from "react"; | ||
import { usePathname } from "next/navigation"; | ||
import { usePathname, useSearchParams } from "next/navigation"; | ||
import Link from "next/link"; | ||
import { | ||
Dialog, | ||
|
@@ -298,6 +298,9 @@ export function SideNav(props: { | |
function Sidebar(props: { isMobile: boolean }) { | ||
const path = usePathname(); | ||
const showMailNav = path === "/mail" || path === "/compose"; | ||
const searchParams = useSearchParams(); | ||
// "?" is added to match the href strings of NavItems | ||
const activePath = `?${showMailNav && searchParams.toString() ? searchParams.toString() : "type=inbox"}`; // if we are at "/mail" only, then the "Inbox" item will be highlighted | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something like this would be cleaner and cover cases where there are other searchParams: const params = new URLSearchParams(searchParams);
params.set(searchParam, value); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has also been changed for better readability and tested as well! |
||
|
||
const { onOpen } = useComposeModal(); | ||
|
||
|
@@ -332,12 +335,12 @@ function Sidebar(props: { isMobile: boolean }) { | |
</Button> | ||
|
||
<div className="mt-2"> | ||
<Links path={path} links={topMailLinks} /> | ||
<Links path={activePath} links={topMailLinks} /> | ||
</div> | ||
<div className="mt-7"> | ||
<NavSectionHeader title="Labels" /> | ||
<div className="mt-2"> | ||
<Links path={path} links={bottomMailLinks} /> | ||
<Links path={activePath} links={bottomMailLinks} /> | ||
</div> | ||
</div> | ||
</Transition> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mostly not using x-primary but the color instead. sometimes primary appears in codebase but it's rare and i'd prefer to stay consistent with colors here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!