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

Fix #201 : Active class for sidebar #221

Merged
merged 4 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 11 additions & 7 deletions apps/web/app/(app)/compose/ComposeEmailForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"use client";

import { Combobox, ComboboxOption, ComboboxOptions } from "@headlessui/react";
import {
Combobox,
ComboboxInput,
ComboboxOption,
ComboboxOptions,
} from "@headlessui/react";
import { CheckCircleIcon, TrashIcon, XIcon } from "lucide-react";
import {
EditorBubble,
Expand Down Expand Up @@ -166,12 +171,12 @@ export const ComposeEmailForm = (props: {
multiple
nullable={true}
>
<div className="flex w-full flex-wrap items-center">
<div className="flex min-h-10 w-full flex-1 flex-wrap items-center gap-2 rounded-md border border-gray-300 px-2 py-2 shadow-sm focus-within:border-black focus-within:ring-black disabled:cursor-not-allowed disabled:bg-gray-50 disabled:text-gray-500 disabled:ring-gray-200 sm:text-sm">
{selectedEmailAddressses.map((emailAddress) => (
<Badge
key={emailAddress}
variant="outline"
className="mr-1.5"
className="h-8 rounded-md border-primary bg-primary text-white"
Copy link
Owner

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

>
{extractNameFromEmail(emailAddress)}

Expand All @@ -185,10 +190,9 @@ export const ComposeEmailForm = (props: {
))}

<div className="relative flex-1">
<Combobox.Input
<ComboboxInput
value={searchQuery}
// styles copied and pasted from Input.tsx
className="block w-full flex-1 rounded-md border-gray-300 shadow-sm focus:border-black focus:ring-black disabled:cursor-not-allowed disabled:bg-gray-50 disabled:text-gray-500 disabled:ring-gray-200 sm:text-sm"
className="w-full border-none py-0 focus:border-none focus:ring-0"
onChange={(event) => setSearchQuery(event.target.value)}
onKeyUp={(event) => {
if (event.key === "Enter") {
Expand Down Expand Up @@ -296,7 +300,7 @@ export const ComposeEmailForm = (props: {
setValue("messageHtml", editor.getHTML());
}}
className={cn(
"relative min-h-32 w-full max-w-screen-lg bg-background sm:rounded-lg",
"relative min-h-32 w-full max-w-screen-lg rounded-xl border bg-background sm:rounded-lg",
props.novelEditorClassName,
)}
editorProps={{
Expand Down
35 changes: 17 additions & 18 deletions apps/web/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,24 @@ export function Modal(props: ModalProps) {
leave="ease-in duration-200"
leaveFrom="opacity-100 scale-100"
leaveTo="opacity-0 scale-95"
className={clsx(
"w-full transform rounded-2xl bg-white text-left align-middle shadow-xl transition-all",
{
"p-6": props.padding === "sm",
"p-10": !props.padding,
"sm:w-full sm:max-w-xl":
!props.fullWidth && (!props.size || props.size === "xl"),
"sm:w-full sm:max-w-2xl":
!props.fullWidth && props.size === "2xl",
"sm:w-full sm:max-w-4xl":
!props.fullWidth && props.size === "4xl",
"sm:w-full sm:max-w-6xl":
!props.fullWidth && props.size === "6xl",
"sm:w-full sm:max-w-full": props.fullWidth,
},
)}
>
<DialogPanel
className={clsx(
"w-full transform rounded-2xl bg-white text-left align-middle shadow-xl transition-all",
{
"p-6": props.padding === "sm",
"p-10": !props.padding,
"sm:w-full sm:max-w-xl":
!props.fullWidth && (!props.size || props.size === "xl"),
"sm:w-full sm:max-w-2xl":
!props.fullWidth && props.size === "2xl",
"sm:w-full sm:max-w-4xl":
!props.fullWidth && props.size === "4xl",
"sm:w-full sm:max-w-6xl":
!props.fullWidth && props.size === "6xl",
"sm:w-full sm:max-w-full": props.fullWidth,
},
)}
>
<DialogPanel>
{props.title && (
<DialogTitle as="h3" className="font-cal text-xl leading-6">
{props.title}
Expand Down
9 changes: 6 additions & 3 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 @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The 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);

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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();

Expand Down Expand Up @@ -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>
Expand Down