Skip to content

Commit f86a86d

Browse files
committed
Improve page load speed for <project>/connect tab by skipping a redirect
1 parent 7fc6191 commit f86a86d

File tree

4 files changed

+60
-44
lines changed

4 files changed

+60
-44
lines changed

apps/dashboard/src/@/components/ui/tabs.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export function TabPathLinks(props: {
199199
path: string;
200200
exactMatch?: boolean;
201201
isDisabled?: boolean;
202+
isActive?: (pathname: string) => boolean;
202203
}[];
203204
className?: string;
204205
tabContainerClassName?: string;
@@ -212,9 +213,11 @@ export function TabPathLinks(props: {
212213
links={links.map((l) => ({
213214
name: l.name,
214215
href: l.path,
215-
isActive: l.exactMatch
216-
? pathname === l.path
217-
: pathname.startsWith(l.path),
216+
isActive: l.isActive
217+
? l.isActive(pathname)
218+
: l.exactMatch
219+
? pathname === l.path
220+
: pathname.startsWith(l.path),
218221
isDisabled: l.isDisabled,
219222
}))}
220223
/>

apps/dashboard/src/app/team/[team_slug]/[project_slug]/connect/page.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { getProject } from "@/api/projects";
2-
import { notFound, redirect } from "next/navigation";
1+
import { redirect } from "next/navigation";
32

43
export default async function Page(props: {
54
params: Promise<{
@@ -8,11 +7,6 @@ export default async function Page(props: {
87
}>;
98
}) {
109
const params = await props.params;
11-
const project = await getProject(params.team_slug, params.project_slug);
12-
13-
if (!project) {
14-
notFound();
15-
}
1610

1711
redirect(
1812
`/team/${params.team_slug}/${params.project_slug}/connect/in-app-wallets`,

apps/dashboard/src/app/team/[team_slug]/[project_slug]/layout.tsx

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { getProjects } from "@/api/projects";
22
import { getTeamNebulaWaitList, getTeams } from "@/api/team";
3-
import { TabPathLinks } from "@/components/ui/tabs";
43
import { notFound, redirect } from "next/navigation";
54
import { getValidAccount } from "../../../account/settings/getAccount";
65
import { TeamHeaderLoggedIn } from "../../components/TeamHeader/team-header-logged-in.client";
6+
import { ProjectTabs } from "./tabs";
77

88
export default async function TeamLayout(props: {
99
children: React.ReactNode;
@@ -55,39 +55,9 @@ export default async function TeamLayout(props: {
5555
teamsAndProjects={teamsAndProjects}
5656
account={account}
5757
/>
58-
<TabPathLinks
59-
tabContainerClassName="px-4 lg:px-6"
60-
links={[
61-
{
62-
path: `/team/${params.team_slug}/${params.project_slug}`,
63-
exactMatch: true,
64-
name: "Overview",
65-
},
66-
{
67-
path: `/team/${params.team_slug}/${params.project_slug}/connect`,
68-
name: "Connect",
69-
},
70-
{
71-
path: `/team/${params.team_slug}/${params.project_slug}/contracts`,
72-
name: "Contracts",
73-
},
74-
...(isOnNebulaWaitList
75-
? [
76-
{
77-
path: `/team/${params.team_slug}/${params.project_slug}/nebula`,
78-
name: "Nebula",
79-
},
80-
]
81-
: []),
82-
{
83-
path: `/team/${params.team_slug}/${params.project_slug}/insight`,
84-
name: "Insight",
85-
},
86-
{
87-
path: `/team/${params.team_slug}/${params.project_slug}/settings`,
88-
name: "Settings",
89-
},
90-
]}
58+
<ProjectTabs
59+
layoutPath={`/team/${params.team_slug}/${params.project_slug}`}
60+
isOnNebulaWaitList={!!isOnNebulaWaitList}
9161
/>
9262
</div>
9363
<div className="flex grow flex-col">{props.children}</div>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"use client";
2+
3+
import { TabPathLinks } from "@/components/ui/tabs";
4+
5+
export function ProjectTabs(props: {
6+
layoutPath: string;
7+
isOnNebulaWaitList: boolean;
8+
}) {
9+
const { layoutPath, isOnNebulaWaitList } = props;
10+
11+
return (
12+
<TabPathLinks
13+
tabContainerClassName="px-4 lg:px-6"
14+
links={[
15+
{
16+
path: layoutPath,
17+
exactMatch: true,
18+
name: "Overview",
19+
},
20+
{
21+
// directly link to /in-app-wallets to skip 1 redirect and use `isActive` for checking if the tab is active or not
22+
path: `${layoutPath}/connect/in-app-wallets`,
23+
name: "Connect",
24+
isActive: (path) => path.startsWith(`${layoutPath}/connect`),
25+
},
26+
{
27+
path: `${layoutPath}/contracts`,
28+
name: "Contracts",
29+
},
30+
...(isOnNebulaWaitList
31+
? [
32+
{
33+
path: `${layoutPath}/nebula`,
34+
name: "Nebula",
35+
},
36+
]
37+
: []),
38+
{
39+
path: `${layoutPath}/insight`,
40+
name: "Insight",
41+
},
42+
{
43+
path: `${layoutPath}/settings`,
44+
name: "Settings",
45+
},
46+
]}
47+
/>
48+
);
49+
}

0 commit comments

Comments
 (0)