Skip to content

Commit c8a4233

Browse files
joetannenbaumWendellAdrielartygrand
authored
Inertia globals (#276)
Co-authored-by: WendellAdriel <[email protected]> Co-authored-by: Arthur Grand <[email protected]>
1 parent 3f21b80 commit c8a4233

9 files changed

Lines changed: 22 additions & 21 deletions

File tree

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public-hoist-pattern[]=@inertiajs/core

resources/js/components/app-header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { useCurrentUrl } from '@/hooks/use-current-url';
3232
import { useInitials } from '@/hooks/use-initials';
3333
import { cn, toUrl } from '@/lib/utils';
3434
import { dashboard } from '@/routes';
35-
import type { BreadcrumbItem, NavItem, SharedData } from '@/types';
35+
import type { BreadcrumbItem, NavItem } from '@/types';
3636
import AppLogo from './app-logo';
3737
import AppLogoIcon from './app-logo-icon';
3838

@@ -65,7 +65,7 @@ const activeItemStyles =
6565
'text-neutral-900 dark:bg-neutral-800 dark:text-neutral-100';
6666

6767
export function AppHeader({ breadcrumbs = [] }: Props) {
68-
const page = usePage<SharedData>();
68+
const page = usePage();
6969
const { auth } = page.props;
7070
const getInitials = useInitials();
7171
const { isCurrentUrl, whenCurrentUrl } = useCurrentUrl();

resources/js/components/app-shell.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { usePage } from '@inertiajs/react';
22
import type { ReactNode } from 'react';
33
import { SidebarProvider } from '@/components/ui/sidebar';
4-
import type { SharedData } from '@/types';
54

65
type Props = {
76
children: ReactNode;
87
variant?: 'header' | 'sidebar';
98
};
109

1110
export function AppShell({ children, variant = 'header' }: Props) {
12-
const isOpen = usePage<SharedData>().props.sidebarOpen;
11+
const isOpen = usePage().props.sidebarOpen;
1312

1413
if (variant === 'header') {
1514
return (

resources/js/components/nav-user.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ import {
1414
import { UserInfo } from '@/components/user-info';
1515
import { UserMenuContent } from '@/components/user-menu-content';
1616
import { useIsMobile } from '@/hooks/use-mobile';
17-
import type { SharedData } from '@/types';
1817

1918
export function NavUser() {
20-
const { auth } = usePage<SharedData>().props;
19+
const { auth } = usePage().props;
2120
const { state } = useSidebar();
2221
const isMobile = useIsMobile();
2322

resources/js/layouts/auth/auth-split-layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Link, usePage } from '@inertiajs/react';
22
import AppLogoIcon from '@/components/app-logo-icon';
33
import { home } from '@/routes';
4-
import type { AuthLayoutProps, SharedData } from '@/types';
4+
import type { AuthLayoutProps } from '@/types';
55

66
export default function AuthSplitLayout({
77
children,
88
title,
99
description,
1010
}: AuthLayoutProps) {
11-
const { name } = usePage<SharedData>().props;
11+
const { name } = usePage().props;
1212

1313
return (
1414
<div className="relative grid h-dvh flex-col items-center justify-center px-8 sm:px-0 lg:max-w-none lg:grid-cols-2 lg:px-0">

resources/js/pages/settings/profile.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import AppLayout from '@/layouts/app-layout';
1111
import SettingsLayout from '@/layouts/settings/layout';
1212
import { edit } from '@/routes/profile';
1313
import { send } from '@/routes/verification';
14-
import type { BreadcrumbItem, SharedData } from '@/types';
14+
import type { BreadcrumbItem } from '@/types';
1515

1616
const breadcrumbs: BreadcrumbItem[] = [
1717
{
@@ -27,7 +27,7 @@ export default function Profile({
2727
mustVerifyEmail: boolean;
2828
status?: string;
2929
}) {
30-
const { auth } = usePage<SharedData>().props;
30+
const { auth } = usePage().props;
3131

3232
return (
3333
<AppLayout breadcrumbs={breadcrumbs}>

resources/js/pages/welcome.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { Head, Link, usePage } from '@inertiajs/react';
22
import { dashboard, login, register } from '@/routes';
3-
import type { SharedData } from '@/types';
43

54
export default function Welcome({
65
canRegister = true,
76
}: {
87
canRegister?: boolean;
98
}) {
10-
const { auth } = usePage<SharedData>().props;
9+
const { auth } = usePage().props;
1110

1211
return (
1312
<>

resources/js/types/global.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { Auth } from '@/types/auth';
2+
3+
declare module '@inertiajs/core' {
4+
export interface InertiaConfig {
5+
sharedPageProps: {
6+
name: string;
7+
auth: Auth;
8+
sidebarOpen: boolean;
9+
[key: string]: unknown;
10+
};
11+
}
12+
}

resources/js/types/index.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
11
export type * from './auth';
22
export type * from './navigation';
33
export type * from './ui';
4-
5-
import type { Auth } from './auth';
6-
7-
export type SharedData = {
8-
name: string;
9-
auth: Auth;
10-
sidebarOpen: boolean;
11-
[key: string]: unknown;
12-
};

0 commit comments

Comments
 (0)