Skip to content
Merged
Show file tree
Hide file tree
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
28 changes: 8 additions & 20 deletions resources/js/components/app-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
} from '@/components/ui/tooltip';
import { UserMenuContent } from '@/components/user-menu-content';
import { useInitials } from '@/hooks/use-initials';
import { cn } from '@/lib/utils';
import { cn, isSameUrl, resolveUrl } from '@/lib/utils';
import { dashboard } from '@/routes';
import { type BreadcrumbItem, type NavItem, type SharedData } from '@/types';
import { Link, usePage } from '@inertiajs/react';
Expand Down Expand Up @@ -118,12 +118,7 @@ export function AppHeader({ breadcrumbs = [] }: AppHeaderProps) {
{rightNavItems.map((item) => (
<a
key={item.title}
href={
typeof item.href ===
'string'
? item.href
: item.href.url
}
href={resolveUrl(item.href)}
target="_blank"
rel="noopener noreferrer"
className="flex items-center space-x-2 font-medium"
Expand Down Expand Up @@ -165,12 +160,10 @@ export function AppHeader({ breadcrumbs = [] }: AppHeaderProps) {
href={item.href}
className={cn(
navigationMenuTriggerStyle(),
page.url ===
(typeof item.href ===
'string'
? item.href
: item.href.url) &&
activeItemStyles,
isSameUrl(
page.url,
item.href,
) && activeItemStyles,
'h-9 cursor-pointer px-3',
)}
>
Expand All @@ -182,7 +175,7 @@ export function AppHeader({ breadcrumbs = [] }: AppHeaderProps) {
)}
{item.title}
</Link>
{page.url === item.href && (
{isSameUrl(page.url, item.href) && (
<div className="absolute bottom-0 left-0 h-0.5 w-full translate-y-px bg-black dark:bg-white"></div>
)}
</NavigationMenuItem>
Expand All @@ -209,12 +202,7 @@ export function AppHeader({ breadcrumbs = [] }: AppHeaderProps) {
<Tooltip>
<TooltipTrigger>
<a
href={
typeof item.href ===
'string'
? item.href
: item.href.url
}
href={resolveUrl(item.href)}
target="_blank"
rel="noopener noreferrer"
className="group ml-1 inline-flex h-9 w-9 items-center justify-center rounded-md bg-transparent p-0 text-sm font-medium text-accent-foreground ring-offset-background transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50"
Expand Down
7 changes: 2 additions & 5 deletions resources/js/components/nav-footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
SidebarMenuButton,
SidebarMenuItem,
} from '@/components/ui/sidebar';
import { resolveUrl } from '@/lib/utils';
import { type NavItem } from '@/types';
import { type ComponentPropsWithoutRef } from 'react';

Expand All @@ -30,11 +31,7 @@ export function NavFooter({
className="text-neutral-600 hover:text-neutral-800 dark:text-neutral-300 dark:hover:text-neutral-100"
>
<a
href={
typeof item.href === 'string'
? item.href
: item.href.url
}
href={resolveUrl(item.href)}
target="_blank"
rel="noopener noreferrer"
>
Expand Down
5 changes: 2 additions & 3 deletions resources/js/components/nav-main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SidebarMenuButton,
SidebarMenuItem,
} from '@/components/ui/sidebar';
import { resolveUrl } from '@/lib/utils';
import { type NavItem } from '@/types';
import { Link, usePage } from '@inertiajs/react';

Expand All @@ -19,9 +20,7 @@ export function NavMain({ items = [] }: { items: NavItem[] }) {
<SidebarMenuButton
asChild
isActive={page.url.startsWith(
typeof item.href === 'string'
? item.href
: item.href.url,
resolveUrl(item.href),
)}
tooltip={{ children: item.title }}
>
Expand Down
13 changes: 6 additions & 7 deletions resources/js/layouts/settings/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Heading from '@/components/heading';
import { Button } from '@/components/ui/button';
import { Separator } from '@/components/ui/separator';
import { cn } from '@/lib/utils';
import { cn, isSameUrl, resolveUrl } from '@/lib/utils';
import { edit as editAppearance } from '@/routes/appearance';
import { edit as editPassword } from '@/routes/password';
import { edit } from '@/routes/profile';
Expand Down Expand Up @@ -53,16 +53,15 @@ export default function SettingsLayout({ children }: PropsWithChildren) {
<nav className="flex flex-col space-y-1 space-x-0">
{sidebarNavItems.map((item, index) => (
<Button
key={`${typeof item.href === 'string' ? item.href : item.href.url}-${index}`}
key={`${resolveUrl(item.href)}-${index}`}
size="sm"
variant="ghost"
asChild
className={cn('w-full justify-start', {
'bg-muted':
currentPath ===
(typeof item.href === 'string'
? item.href
: item.href.url),
'bg-muted': isSameUrl(
currentPath,
item.href,
),
})}
>
<Link href={item.href}>
Expand Down
12 changes: 12 additions & 0 deletions resources/js/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { InertiaLinkProps } from '@inertiajs/react';
import { type ClassValue, clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

export function isSameUrl(
url1: NonNullable<InertiaLinkProps['href']>,
url2: NonNullable<InertiaLinkProps['href']>,
) {
return resolveUrl(url1) === resolveUrl(url2);
}

export function resolveUrl(url: NonNullable<InertiaLinkProps['href']>): string {
return typeof url === 'string' ? url : url.url;
}