Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Update sidebar-nav.tsx

Tim Wilson5683cbe464ad
diff --git a/apps/web/ui/layout/sidebar/sidebar-nav.tsx b/apps/web/ui/layout/sidebar/sidebar-nav.tsx
index 9ea7c0d71f..22a1757ccd 100644
--- a/apps/web/ui/layout/sidebar/sidebar-nav.tsx
+++ b/apps/web/ui/layout/sidebar/sidebar-nav.tsx
@@ -10,12 +10,14 @@ import { ITEMS, type NavItem } from "./items";
import UserDropdown from "./user-dropdown";
import { WorkspaceDropdown } from "./workspace-dropdown";
+const AREAS = ["userSettings", "workspaceSettings", "default"] as const;
+
export function SidebarNav({ toolContent }: { toolContent?: ReactNode }) {
const { slug } = useParams() as { slug?: string };
const { flags } = useWorkspace();
const pathname = usePathname();
- const area = useMemo(() => {
+ const currentArea = useMemo(() => {
return pathname.startsWith("/account/settings")
? "userSettings"
: pathname.startsWith(`/${slug}/settings`)
@@ -23,34 +25,38 @@ export function SidebarNav({ toolContent }: { toolContent?: ReactNode }) {
: "default";
}, [slug, pathname]);
- const itemGroups = useMemo(() => ITEMS[area], [area]);
-
return (
<div className="relative p-3 text-gray-500">
- <div className="relative mb-7 flex items-start justify-between gap-1">
- <AnimatePresence>
- <motion.div
- key={area}
- initial={{ opacity: 0 }}
- animate={{ opacity: 1 }}
- exit={{
- opacity: 0,
- position: "absolute",
- }}
- transition={{ duration: 0.15, ease: "easeInOut" }}
- className="left-0 top-0"
- >
- <Link href={slug ? `/${slug}` : "/"}>
- {area === "default" ? (
- <Wordmark className="ml-1 h-6" />
- ) : (
- <div className="group -my-1 flex items-center gap-2 py-2 text-sm font-medium text-neutral-900">
- <ChevronLeft className="size-4 text-neutral-500 transition-transform duration-100 group-hover:-translate-x-0.5" />
- Settings
- </div>
- )}
- </Link>
- </motion.div>
+ <div className="relative flex items-start justify-between gap-1 pb-3">
+ <AnimatePresence initial={false}>
+ {AREAS.map((area) =>
+ area === currentArea ? (
+ <motion.div
+ key={area}
+ initial={{ opacity: 0 }}
+ animate={{ opacity: 1 }}
+ exit={{
+ opacity: 0,
+ position: "absolute",
+ }}
+ transition={{ duration: 0.15, ease: "easeInOut" }}
+ className="left-0 top-0"
+ >
+ <Link href={slug ? `/${slug}` : "/"}>
+ {area === "default" ? (
+ <div className="pb-1">
+ <Wordmark className="ml-1 h-6" />
+ </div>
+ ) : (
+ <div className="py group -my-1 flex items-center gap-2 py-2 text-sm font-medium text-neutral-900">
+ <ChevronLeft className="size-4 text-neutral-500 transition-transform duration-100 group-hover:-translate-x-0.5" />
+ Settings
+ </div>
+ )}
+ </Link>
+ </motion.div>
+ ) : null,
+ )}
</AnimatePresence>
<div className="hidden items-center gap-3 md:flex">
<Suspense fallback={null}>{toolContent}</Suspense>
@@ -58,40 +64,54 @@ export function SidebarNav({ toolContent }: { toolContent?: ReactNode }) {
</div>
</div>
<div className="relative w-full">
- <AnimatePresence>
- <motion.div
- key={area}
- className="relative left-0 top-0 w-full"
- initial={{ opacity: 0, x: area === "default" ? "-100%" : "100%" }}
- animate={{ opacity: 1, x: 0 }}
- exit={{
- opacity: 0,
- position: "absolute",
- x: area === "default" ? "-100%" : "100%",
- }}
- transition={{ duration: 0.15, ease: "easeInOut" }}
- >
- {area === "default" && (
- <div className="mt-7">
- <WorkspaceDropdown />
- </div>
- )}
+ <AnimatePresence initial={false}>
+ {AREAS.map((area) =>
+ area === currentArea ? (
+ <motion.div
+ key={area}
+ className="relative left-0 top-0 w-full"
+ initial={{
+ opacity: 0,
+ x: area === "default" ? "-100%" : "100%",
+ }}
+ animate={{ opacity: 1, x: 0 }}
+ exit={{
+ opacity: 0,
+ position: "absolute",
+ x: area === "default" ? "-100%" : "100%",
+ }}
+ transition={{ duration: 0.15, ease: "easeInOut" }}
+ >
+ {area === "default" && (
+ <div className="pt-2">
+ <WorkspaceDropdown />
+ </div>
+ )}
- <div className="mt-4 flex flex-col gap-4">
- {itemGroups.map(({ name, items }, idx) => (
- <div key={`${name}-${idx}`} className="flex flex-col gap-0.5">
- {name && (
- <div className="mb-2 pl-1 text-sm text-neutral-500">
- {name}
+ <div className="flex flex-col gap-4 pt-4">
+ {ITEMS[area].map(({ name, items }, idx) => (
+ <div
+ key={`${name}-${idx}`}
+ className="flex flex-col gap-0.5"
+ >
+ {name && (
+ <div className="mb-2 pl-1 text-sm text-neutral-500">
+ {name}
+ </div>
+ )}
+ {items({ slug: slug || "", flags }).map((item) => (
+ <NavItem
+ key={item.name}
+ pathname={pathname}
+ item={item}
+ />
+ ))}
</div>
- )}
- {items({ slug: slug || "", flags }).map((item) => (
- <NavItem key={item.name} pathname={pathname} item={item} />
))}
</div>
- ))}
- </div>
- </motion.div>
+ </motion.div>
+ ) : null,
+ )}
</AnimatePresence>
</div>
</div>