Skip to content

Commit 1dfd082

Browse files
author
aXenDeveloper
committed
refactor(auth): 🔗 replace LinkComponent with Link from @tanstack/react-router
1 parent 999606b commit 1dfd082

82 files changed

Lines changed: 252 additions & 915 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/create-vitnode-app/copy-of-vitnode-app/root/src/routes/_main/index.tsx‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import type { LucideIcon } from "lucide-react";
22

3-
import { createFileRoute } from "@tanstack/react-router";
3+
import type { RegisteredRouter } from "@tanstack/react-router";
4+
5+
import { createFileRoute, Link } from "@tanstack/react-router";
46
import { LogoVitNode } from "@vitnode/core/components/logo-vitnode";
57
import { buttonVariants } from "@vitnode/core/components/ui/button";
68
import {
79
VITNODE_DOCS_URL,
810
VITNODE_WEBSITE_URL,
911
} from "@vitnode/core/lib/docs-links";
1012
import { useSessionQuery } from "@vitnode/core/tanstack/auth";
11-
import { RouterLink } from "@vitnode/core/tanstack/layout";
1213
import { pageHead } from "@vitnode/core/tanstack/metadata";
1314
import { cn } from "cn";
1415
import {
@@ -95,28 +96,28 @@ function HomeRoute() {
9596

9697
<div className="flex flex-col gap-3 sm:flex-row">
9798
{user ? null : (
98-
<RouterLink
99+
<Link
99100
className={cn(buttonVariants({ size: "lg" }), "px-5")}
100-
href={REGISTER_HREF}
101+
to={REGISTER_HREF}
101102
>
102103
<UserRoundPlus />
103104
Create an account
104-
</RouterLink>
105+
</Link>
105106
)}
106107

107-
<RouterLink
108+
<Link
108109
className={cn(
109110
buttonVariants({
110111
size: "lg",
111112
variant: user ? "default" : "outline",
112113
}),
113114
"px-5",
114115
)}
115-
href={ADMIN_HREF}
116+
to={ADMIN_HREF}
116117
>
117118
<ShieldCheck />
118119
Open AdminCP
119-
</RouterLink>
120+
</Link>
120121
</div>
121122
</section>
122123

@@ -188,8 +189,8 @@ function NextStepCard({
188189
}
189190

190191
return (
191-
<RouterLink className={className} href={href}>
192+
<Link<RegisteredRouter, string, string> className={className} href={href}>
192193
{content}
193-
</RouterLink>
194+
</Link>
194195
);
195196
}

‎packages/vitnode/src/components/ui/header-content.tsx‎

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Link } from "@tanstack/react-router";
12
import { cn } from "cn";
23
import { ArrowLeftIcon } from "lucide-react";
34

@@ -18,34 +19,18 @@ export interface HeaderContentBack {
1819
label: React.ReactNode;
1920
}
2021

21-
export interface HeaderContentBackLinkProps extends Omit<
22-
React.ComponentProps<"a">,
23-
"href"
24-
> {
25-
href: string;
26-
}
27-
28-
export type HeaderContentBackLinkComponent = (
29-
props: HeaderContentBackLinkProps,
30-
) => React.ReactNode;
31-
32-
type HeaderContentBackProps =
33-
| { back: HeaderContentBack; BackLink: HeaderContentBackLinkComponent }
34-
| { back?: never; BackLink?: never };
35-
3622
interface HeaderContentBaseProps {
23+
back?: HeaderContentBack;
3724
children?: React.ReactNode;
3825
className?: string;
3926
desc?: React.ReactNode;
4027
ref?: React.RefCallback<HTMLDivElement>;
4128
}
4229

43-
export type HeaderContentProps = HeaderContentBackProps &
44-
HeaderContentBaseProps &
30+
export type HeaderContentProps = HeaderContentBaseProps &
4531
(HeaderContentH1Props | HeaderContentH2Props);
4632

4733
export const HeaderContent = ({
48-
BackLink,
4934
back,
5035
children,
5136
className,
@@ -77,10 +62,10 @@ export const HeaderContent = ({
7762

7863
{!!back || !!children ? (
7964
<div className="flex w-full flex-col flex-wrap items-center justify-center gap-2 sm:w-auto sm:flex-row [&>*]:w-full [&>*]:sm:w-auto">
80-
{back && BackLink ? (
65+
{back ? (
8166
<Button
8267
nativeButton={false}
83-
render={<BackLink href={back.href} />}
68+
render={<Link to={back.href} />}
8469
variant="outline"
8570
>
8671
<ArrowLeftIcon />

‎packages/vitnode/src/tanstack/admin/breadcrumb.tsx‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { useMatches, useRouter } from "@tanstack/react-router";
22

3-
import type { AuthLinkComponent } from "@/views/auth/auth-link";
4-
53
import { BreadcrumbAdminContent } from "@/views/admin/layouts/breadcrumb/breadcrumb-admin-content";
64
import { BreadcrumbTrailContent } from "@/views/breadcrumb/breadcrumb-trail-content";
75

86
import type { RouteBreadcrumbGroup } from "../breadcrumb/model";
97

108
import { breadcrumbGroup, breadcrumbTrail } from "../breadcrumb/model";
11-
import { RouterLink } from "../layout/router-link";
129
import { useRouteNavigationPending } from "../pending/navigation-pending";
1310
import { BreadcrumbPendingSkeleton } from "../pending/shapes";
1411
import { useAdminNav } from "./nav";
@@ -28,22 +25,18 @@ export const useAdminBreadcrumb = (): React.ReactNode => {
2825

2926
export const AdminBreadcrumb = ({
3027
labels,
31-
LinkComponent = RouterLink,
3228
overrideLastLabel,
3329
segments,
3430
}: {
3531
/** Explicit labels by href, for a crumb the navigation cannot name. */
3632
labels?: Record<string, string>;
37-
LinkComponent?: AuthLinkComponent;
3833
/** The last crumb's label, when the page knows it and the navigation cannot. */
3934
overrideLastLabel?: string;
4035
/** The path below `/admin`, e.g. `["core", "users"]`. */
4136
segments: string[];
4237
}) => (
4338
<BreadcrumbAdminContent
4439
labels={labels}
45-
LinkComponent={LinkComponent}
46-
4740
nav={useAdminNav()}
4841
overrideLastLabel={overrideLastLabel}
4942
segments={segments}

‎packages/vitnode/src/tanstack/admin/content/breadcrumb.tsx‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
import { useTranslations } from "use-intl";
22

3-
import type { AuthLinkComponent } from "@/views/auth/auth-link";
4-
53
import type { ContentBreadcrumbModel } from "./breadcrumb-model";
64
import type { ContentAdminRouteData } from "./route";
75

86
import { RouteMessages } from "../../i18n/route-messages";
97
import { AdminBreadcrumb } from "../breadcrumb";
108
import { contentBreadcrumbModel } from "./breadcrumb-model";
119

12-
export interface ContentAdminBreadcrumbProps extends Partial<
10+
export type ContentAdminBreadcrumbProps = Partial<
1311
Pick<ContentAdminRouteData, "action" | "adminPath" | "labels" | "namespaces">
14-
> {
15-
LinkComponent?: AuthLinkComponent;
16-
}
12+
>;
1713

1814
export const ContentAdminBreadcrumbContent = ({
19-
LinkComponent,
2015
namespaces,
2116
...route
2217
}: ContentAdminBreadcrumbProps) => {
@@ -30,30 +25,26 @@ export const ContentAdminBreadcrumbContent = ({
3025
<RouteMessages namespaces={namespaces ?? []}>
3126
{model.kind === "list" ? (
3227
<AdminBreadcrumb
33-
LinkComponent={LinkComponent}
3428
overrideLastLabel={model.title}
3529
segments={model.segments}
3630
/>
3731
) : (
38-
<ContentFormCrumb LinkComponent={LinkComponent} model={model} />
32+
<ContentFormCrumb model={model} />
3933
)}
4034
</RouteMessages>
4135
);
4236
};
4337

4438
const ContentFormCrumb = ({
45-
LinkComponent,
4639
model,
4740
}: {
48-
LinkComponent?: AuthLinkComponent;
4941
model: Extract<ContentBreadcrumbModel, { kind: "form" }>;
5042
}) => {
5143
const t = useTranslations("core.content");
5244

5345
return (
5446
<AdminBreadcrumb
5547
labels={{ [model.listHref]: model.title }}
56-
LinkComponent={LinkComponent}
5748
overrideLastLabel={t(
5849
model.action === "create" ? "create.title" : "edit.title",
5950
{ name: model.singular },

‎packages/vitnode/src/tanstack/admin/content/create-action.tsx‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1+
import { Link } from "@tanstack/react-router";
12
import { PlusIcon } from "lucide-react";
23
import { useTranslations } from "use-intl";
34

45
import type { RegisteredFrontendContentType } from "@/content/index";
5-
import type { AuthLinkComponent } from "@/views/auth/auth-link";
66

77
import { Button } from "@/components/ui/button";
88
import { CONTENT_PERMISSIONS, contentCreateHref } from "@/content/index";
99

10-
import { RouterLink } from "../../layout/router-link";
1110
import { useAdminPermission } from "../permissions";
1211
import { ContentFormDialogSlot } from "./slot-render";
1312
import { contentAdminSlots } from "./slots";
1413

1514
export const ContentCreateAction = ({
1615
entry,
17-
LinkComponent = RouterLink,
1816
singular,
1917
}: {
2018
entry: RegisteredFrontendContentType;
21-
/** How a path becomes a navigation. See {@link RouterLink} for the default. */
22-
LinkComponent?: AuthLinkComponent;
2319
singular: string;
2420
}) => {
2521
const { definition, pluginId } = entry;
@@ -39,7 +35,7 @@ export const ContentCreateAction = ({
3935
return (
4036
<Button
4137
nativeButton={false}
42-
render={<LinkComponent href={contentCreateHref(definition)} />}
38+
render={<Link to={contentCreateHref(definition)} />}
4339
>
4440
<PlusIcon />
4541
{label}

‎packages/vitnode/src/tanstack/admin/content/editorial/host.tsx‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,16 @@ import { useRouter } from "@tanstack/react-router";
33
import React from "react";
44

55
import type { ContentFormNavigation } from "@/views/admin/views/content/form/navigation";
6-
import type { AuthLinkComponent } from "@/views/auth/auth-link";
76

87
import { ContentEditorialTransportProvider } from "@/views/admin/views/content/actions/editorial-transport";
98
import { ContentFormNavigationProvider } from "@/views/admin/views/content/form/navigation";
109

11-
import { RouterLink } from "../../../layout/router-link";
1210
import { contentEditorialTransport } from "./transport";
1311

1412
export const ContentEditorialHost = ({
1513
children,
16-
LinkComponent = RouterLink,
1714
}: {
1815
children: React.ReactNode;
19-
/** How a path becomes a navigation. See {@link RouterLink} for the default. */
20-
LinkComponent?: AuthLinkComponent;
2116
}) => {
2217
const queryClient = useQueryClient();
2318
const router = useRouter();
@@ -29,15 +24,14 @@ export const ContentEditorialHost = ({
2924

3025
const navigation = React.useMemo<ContentFormNavigation>(
3126
() => ({
32-
LinkComponent,
3327
navigate: href => {
3428
void router.navigate({ href });
3529
},
3630
refresh: () => {
3731
void router.invalidate();
3832
},
3933
}),
40-
[LinkComponent, router],
34+
[router],
4135
);
4236

4337
return (

‎packages/vitnode/src/tanstack/admin/content/form/host.tsx‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,16 @@ import { useRouter } from "@tanstack/react-router";
33
import React from "react";
44

55
import type { ContentFormNavigation } from "@/views/admin/views/content/form/navigation";
6-
import type { AuthLinkComponent } from "@/views/auth/auth-link";
76

87
import { ContentFormNavigationProvider } from "@/views/admin/views/content/form/navigation";
98
import { ContentFormTransportProvider } from "@/views/admin/views/content/form/transport";
109

11-
import { RouterLink } from "../../../layout/router-link";
1210
import { contentFormTransport } from "./transport";
1311

1412
export const ContentFormHost = ({
1513
children,
16-
LinkComponent = RouterLink,
1714
}: {
1815
children: React.ReactNode;
19-
/** How a path becomes a navigation. See {@link RouterLink} for the default. */
20-
LinkComponent?: AuthLinkComponent;
2116
}) => {
2217
const queryClient = useQueryClient();
2318
const router = useRouter();
@@ -29,15 +24,14 @@ export const ContentFormHost = ({
2924

3025
const navigation = React.useMemo<ContentFormNavigation>(
3126
() => ({
32-
LinkComponent,
3327
navigate: href => {
3428
void router.navigate({ href });
3529
},
3630
refresh: () => {
3731
void router.invalidate();
3832
},
3933
}),
40-
[LinkComponent, router],
34+
[router],
4135
);
4236

4337
return (

‎packages/vitnode/src/tanstack/admin/content/form/screen.tsx‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from "react";
22

33
import type { ContentFrontendRegistry } from "@/content/index";
4-
import type { AuthLinkComponent } from "@/views/auth/auth-link";
54

65
import type { ContentAdminRouteData } from "../route";
76
import type { ContentFormScreenData } from "./route";
@@ -17,14 +16,11 @@ const ContentFormPageBody = React.lazy(async () =>
1716

1817
export interface ContentFormScreenProps
1918
extends ContentAdminRouteData, ContentFormScreenData {
20-
/** How a path becomes a navigation. Defaults to the router's own link. */
21-
LinkComponent?: AuthLinkComponent;
2219
/** This installation's content types, with their override components. */
2320
registry: ContentFrontendRegistry;
2421
}
2522

2623
export const ContentFormScreen = ({
27-
LinkComponent,
2824
registry,
2925
...route
3026
}: ContentFormScreenProps) => {
@@ -33,7 +29,7 @@ export const ContentFormScreen = ({
3329
if (route.action === "list" || !entry) return null;
3430

3531
return (
36-
<ContentFormHost LinkComponent={LinkComponent}>
32+
<ContentFormHost>
3733
{/*
3834
* The boundary the lazy body suspends against.
3935
*

0 commit comments

Comments
 (0)