Skip to content
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

Added active class to alpha mail sidebar #202

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions apps/web/components/SideNav.tsx
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,
Expand Down Expand Up @@ -297,6 +297,9 @@ export function SideNav(props: {

function Sidebar(props: { isMobile: boolean }) {
const path = usePathname();
const params = useSearchParams();
const typeParams = params.get("type");

const showMailNav = path === "/mail" || path === "/compose";

const { onOpen } = useComposeModal();
Expand Down Expand Up @@ -332,12 +335,15 @@ function Sidebar(props: { isMobile: boolean }) {
</Button>

<div className="mt-2">
<Links path={path} links={topMailLinks} />
<Links path={`${path}?type=${typeParams}`} links={topMailLinks} />
</div>
<div className="mt-7">
<NavSectionHeader title="Labels" />
<div className="mt-2">
<Links path={path} links={bottomMailLinks} />
<Links
path={`${path}?type=${typeParams}`}
links={bottomMailLinks}
/>
</div>
</div>
</Transition>
Expand Down Expand Up @@ -392,14 +398,15 @@ function Links(props: { path: string; links: NavItem[] }) {

function NavLink(props: { path: string; link: NavItem }) {
const { link } = props;
const isActive = props.path === link.href || props.path.includes(link.href);
Copy link
Owner

Choose a reason for hiding this comment

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

What was the reason for includes here?
But also includes would match === too.

Copy link
Author

@Vishvsalvi Vishvsalvi Jul 28, 2024

Choose a reason for hiding this comment

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

The includes matches the query string, === doesn't match the query string it is for the paths.

Copy link
Owner

@elie222 elie222 Aug 1, 2024

Choose a reason for hiding this comment

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

If props.path.includes(link.href) is true then it must be that props.path === link.href is true

Copy link
Author

Choose a reason for hiding this comment

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

Ohh I haven't checked that yet! If that's the case I'll make the changes


return (
<li key={link.name}>
<Link
href={link.href}
className={clsx(
"group flex h-9 items-center gap-x-3 rounded-md px-3 text-sm font-semibold leading-5 text-white",
link.href === props.path ? "bg-gray-800" : "hover:bg-gray-800",
isActive ? "bg-gray-800" : "hover:bg-gray-800",
)}
target={link.target}
prefetch={link.target !== "_blank"}
Expand Down