Skip to content

Commit d19526d

Browse files
committed
perf(ui): optimize header render
1 parent cfe6d62 commit d19526d

File tree

8 files changed

+39
-47
lines changed

8 files changed

+39
-47
lines changed

app/[locale]/(private)/profile/dynamic.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
2-
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
3-
import { Label } from "@/components/ui/label";
2+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
43
import { User } from "@supabase/supabase-js";
54
import { getTranslations } from "next-intl/server";
65

@@ -25,11 +24,6 @@ const Profile = async ({ user }: { user: User }) => {
2524
</div>
2625
</div>
2726
</CardContent>
28-
<CardFooter className='flex justify-center'>
29-
<Label className='uppercase font-bold text-center'>
30-
{t("loginWith")} {user?.app_metadata.provider}
31-
</Label>
32-
</CardFooter>
3327
</Card>
3428
);
3529
};

app/api/auth/callback/route.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export async function GET(request: Request) {
1212
if (!error) {
1313
const forwardedHost = request.headers.get("x-forwarded-host");
1414
const isLocalEnv = process.env.NODE_ENV === "development";
15+
1516
if (isLocalEnv) {
1617
return NextResponse.redirect(`${origin}${next}`);
1718
} else if (forwardedHost) {
@@ -21,6 +22,7 @@ export async function GET(request: Request) {
2122
}
2223
}
2324
}
25+
2426
// TODO: Redirect to error page
2527
return NextResponse.redirect(`${origin}/auth/auth-code-error`);
2628
}
File renamed without changes.

components/custom/Header.tsx

Lines changed: 0 additions & 33 deletions
This file was deleted.

components/custom/LocaleSelect.tsx renamed to components/custom/Header/LocalSlelect.client.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
"use client";
22

3-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select";
4-
import { useTranslations, useLocale } from "next-intl";
3+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../ui/select";
4+
import { useLocale, useTranslations } from "next-intl";
55
import { usePathname, useRouter } from "@/configs/i18n/routing";
66
import { useTransition } from "react";
7+
import { Skeleton } from "@/components/ui/skeleton";
78

89
const LocaleSelect = () => {
910
const t = useTranslations("common.locale");
10-
1111
const [isPending, startTransition] = useTransition();
1212
const locale = useLocale();
1313
const router = useRouter();
1414
const pathname = usePathname();
1515

16-
const handleChangeLocale = async (newLocale: string) => {
16+
const handleChangeLocale = (newLocale: string) => {
1717
startTransition(() => {
1818
router.replace({ pathname }, { locale: newLocale });
1919
});
2020
};
2121

2222
if (isPending) {
23-
return null;
23+
return <Skeleton className='h-10 w-[180px] border-2' />;
2424
}
2525

2626
return (
File renamed without changes.

components/custom/UserProfile.tsx renamed to components/custom/Header/UserProfile.client.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
DropdownMenuItem,
77
DropdownMenuTrigger
88
} from "@/components/ui/dropdown-menu";
9-
import { Button } from "../ui/button";
9+
import { Button } from "../../ui/button";
1010
import { useEffect, useState } from "react";
1111
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
1212
import { createClient } from "@/configs/supabase/client";
@@ -15,6 +15,7 @@ import { _ROUTE_AUTH, _ROUTE_PROFILE } from "@/constants/route";
1515
import { useRouter } from "@/configs/i18n/routing";
1616
import { User } from "@supabase/supabase-js";
1717
import { useTranslations } from "next-intl";
18+
import { Skeleton } from "../../ui/skeleton";
1819

1920
const UserProfile = () => {
2021
const t = useTranslations("common.nav");
@@ -44,7 +45,7 @@ const UserProfile = () => {
4445
}, []);
4546

4647
if (loading) {
47-
return null;
48+
return <Skeleton className='h-10 w-10 rounded-full' />;
4849
}
4950

5051
return user ? (

components/custom/Header/index.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { useTranslations } from "next-intl";
2+
import { Link } from "@/configs/i18n/routing";
3+
import { ModeToggle } from "./ModeToggle.client";
4+
import { UserProfile } from "./UserProfile.client";
5+
import { LocaleSelect } from "./LocalSlelect.client";
6+
7+
const Header = () => {
8+
const tHeader = useTranslations("header");
9+
10+
return (
11+
<header className='shadow-md border-b-2'>
12+
<div className='container mx-auto px-4 py-4 flex justify-between items-center'>
13+
<div className='flex items-center uppercase font-bold text-xl'>
14+
<Link prefetch={true} href='/'>
15+
{tHeader("logoName")}
16+
</Link>
17+
</div>
18+
<div className='flex gap-2'>
19+
<LocaleSelect />
20+
<ModeToggle />
21+
<UserProfile />
22+
</div>
23+
</div>
24+
</header>
25+
);
26+
};
27+
28+
export { Header };

0 commit comments

Comments
 (0)