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
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
php-version: ['8.4', '8.5']

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v6

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
],
"dev": [
"Composer\\Config::disableProcessTimeout",
"npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite --kill-others"
"npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1 --timeout=0\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite --kill-others"
],
"dev:ssr": [
"npm run build:ssr",
Expand Down
2 changes: 1 addition & 1 deletion config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => rtrim(env('APP_URL'), '/').'/storage',
'url' => rtrim(env('APP_URL', 'http://localhost'), '/').'/storage',
'visibility' => 'public',
'throw' => false,
'report' => false,
Expand Down
4 changes: 2 additions & 2 deletions database/migrations/0001_01_01_000001_create_cache_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public function up(): void
Schema::create('cache', function (Blueprint $table) {
$table->string('key')->primary();
$table->mediumText('value');
$table->integer('expiration');
$table->integer('expiration')->index();
});

Schema::create('cache_locks', function (Blueprint $table) {
$table->string('key')->primary();
$table->string('owner');
$table->integer('expiration');
$table->integer('expiration')->index();
});
}

Expand Down
10 changes: 6 additions & 4 deletions resources/js/components/app-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
TooltipTrigger,
} from '@/components/ui/tooltip';
import { UserMenuContent } from '@/components/user-menu-content';
import { useActiveUrl } from '@/hooks/use-active-url';
import { useCurrentUrl } from '@/hooks/use-current-url';
import { useInitials } from '@/hooks/use-initials';
import { cn, toUrl } from '@/lib/utils';
import { dashboard } from '@/routes';
Expand Down Expand Up @@ -70,7 +70,7 @@ export function AppHeader({ breadcrumbs = [] }: AppHeaderProps) {
const page = usePage<SharedData>();
const { auth } = page.props;
const getInitials = useInitials();
const { urlIsActive } = useActiveUrl();
const { isCurrentUrl, whenCurrentUrl } = useCurrentUrl();
return (
<>
<div className="border-b border-sidebar-border/80">
Expand Down Expand Up @@ -157,8 +157,10 @@ export function AppHeader({ breadcrumbs = [] }: AppHeaderProps) {
href={item.href}
className={cn(
navigationMenuTriggerStyle(),
urlIsActive(item.href) &&
whenCurrentUrl(
item.href,
activeItemStyles,
),
'h-9 cursor-pointer px-3',
)}
>
Expand All @@ -167,7 +169,7 @@ export function AppHeader({ breadcrumbs = [] }: AppHeaderProps) {
)}
{item.title}
</Link>
{urlIsActive(item.href) && (
{isCurrentUrl(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 Down
6 changes: 3 additions & 3 deletions resources/js/components/nav-main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
SidebarMenuButton,
SidebarMenuItem,
} from '@/components/ui/sidebar';
import { useActiveUrl } from '@/hooks/use-active-url';
import { useCurrentUrl } from '@/hooks/use-current-url';
import { type NavItem } from '@/types';

export function NavMain({ items = [] }: { items: NavItem[] }) {
const { urlIsActive } = useActiveUrl();
const { isCurrentUrl } = useCurrentUrl();

return (
<SidebarGroup className="px-2 py-0">
Expand All @@ -21,7 +21,7 @@ export function NavMain({ items = [] }: { items: NavItem[] }) {
<SidebarMenuItem key={item.title}>
<SidebarMenuButton
asChild
isActive={urlIsActive(item.href)}
isActive={isCurrentUrl(item.href)}
tooltip={{ children: item.title }}
>
<Link href={item.href} prefetch>
Expand Down
22 changes: 0 additions & 22 deletions resources/js/hooks/use-active-url.ts

This file was deleted.

42 changes: 42 additions & 0 deletions resources/js/hooks/use-current-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { InertiaLinkProps } from '@inertiajs/react';
import { usePage } from '@inertiajs/react';

import { toUrl } from '@/lib/utils';

export function useCurrentUrl() {
const page = usePage();
const currentUrlPath = new URL(page.url, window?.location.origin).pathname;

function isCurrentUrl(
urlToCheck: NonNullable<InertiaLinkProps['href']>,
currentUrl?: string,
) {
const urlToCompare = currentUrl ?? currentUrlPath;
const urlString = toUrl(urlToCheck);

if (!urlString.startsWith('http')) {
return urlString === urlToCompare;
}

try {
const absoluteUrl = new URL(urlString);
return absoluteUrl.pathname === urlToCompare;
} catch {
return false;
}
}

function whenCurrentUrl(
urlToCheck: NonNullable<InertiaLinkProps['href']>,
ifTrue,
ifFalse = null,
) {
return isCurrentUrl(urlToCheck) ? ifTrue : ifFalse;
}

return {
currentUrl: currentUrlPath,
isCurrentUrl,
whenCurrentUrl,
};
}
6 changes: 3 additions & 3 deletions resources/js/layouts/settings/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type PropsWithChildren } from 'react';
import Heading from '@/components/heading';
import { Button } from '@/components/ui/button';
import { Separator } from '@/components/ui/separator';
import { useActiveUrl } from '@/hooks/use-active-url';
import { useCurrentUrl } from '@/hooks/use-current-url';
import { cn, toUrl } from '@/lib/utils';
import { edit as editAppearance } from '@/routes/appearance';
import { edit } from '@/routes/profile';
Expand Down Expand Up @@ -36,7 +36,7 @@ const sidebarNavItems: NavItem[] = [
];

export default function SettingsLayout({ children }: PropsWithChildren) {
const { urlIsActive } = useActiveUrl();
const { isCurrentUrl } = useCurrentUrl();

// When server-side rendering, we only render the layout on the client...
if (typeof window === 'undefined') {
Expand All @@ -63,7 +63,7 @@ export default function SettingsLayout({ children }: PropsWithChildren) {
variant="ghost"
asChild
className={cn('w-full justify-start', {
'bg-muted': urlIsActive(item.href),
'bg-muted': isCurrentUrl(item.href),
})}
>
<Link href={item.href}>
Expand Down
Loading