perf(home): shrink carousel client boundary
This commit is contained in:
+1
-1
@@ -24,7 +24,7 @@ export default async function Home() {
|
|||||||
// Use configured profile data.
|
// Use configured profile data.
|
||||||
const profileName = config.profile.name;
|
const profileName = config.profile.name;
|
||||||
const profileAvatar = config.profile.avatar;
|
const profileAvatar = config.profile.avatar;
|
||||||
const links1 = [...config.links];
|
const links1 = config.links;
|
||||||
|
|
||||||
const jsonLd = {
|
const jsonLd = {
|
||||||
"@context": "https://schema.org",
|
"@context": "https://schema.org",
|
||||||
|
|||||||
+61
-57
@@ -1,14 +1,15 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
import { useState } from "react";
|
|
||||||
import type { ComponentType, SVGProps } from "react";
|
import type { ComponentType, SVGProps } from "react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { CardContent } from "@/components/ui/card";
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { ArrowLeft, ArrowRight, Trophy } from "lucide-react";
|
import { Trophy } from "lucide-react";
|
||||||
import { LinkConfig, type IconName } from "@/lib/config";
|
import type { LinkConfig, IconName } from "@/lib/config";
|
||||||
import { getCountForLink, formatCount, FollowerCounts } from "@/lib/followers/utils";
|
import {
|
||||||
|
getCountForLink,
|
||||||
|
formatCount,
|
||||||
|
type FollowerCounts,
|
||||||
|
} from "@/lib/followers/utils";
|
||||||
import { RobloxIcon, DiscordIcon, TiktokIcon, YoutubeIcon, FormIcon, DonateIcon } from "@/lib/icons";
|
import { RobloxIcon, DiscordIcon, TiktokIcon, YoutubeIcon, FormIcon, DonateIcon } from "@/lib/icons";
|
||||||
|
import { LinkCarousel } from "@/components/link-carousel";
|
||||||
|
|
||||||
const iconMap: Record<IconName, ComponentType<SVGProps<SVGSVGElement>>> = {
|
const iconMap: Record<IconName, ComponentType<SVGProps<SVGSVGElement>>> = {
|
||||||
roblox: RobloxIcon,
|
roblox: RobloxIcon,
|
||||||
@@ -20,71 +21,74 @@ const iconMap: Record<IconName, ComponentType<SVGProps<SVGSVGElement>>> = {
|
|||||||
leaderboard: Trophy,
|
leaderboard: Trophy,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function LinkCard({ counts, links1, links2 }: { counts: FollowerCounts, links1: LinkConfig[], links2: LinkConfig[] }) {
|
function LinkList({
|
||||||
const [isPage2, setIsPage2] = useState(false);
|
counts,
|
||||||
const currentLinks = isPage2 ? links2 : links1;
|
label,
|
||||||
|
links,
|
||||||
|
}: {
|
||||||
|
counts: FollowerCounts;
|
||||||
|
label: string;
|
||||||
|
links: readonly LinkConfig[];
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<CardContent>
|
<nav aria-label={label} className="flex flex-col gap-3">
|
||||||
<div key={isPage2 ? "p2" : "p1"} className="animate-in fade-in slide-in-from-bottom-2 duration-150">
|
{links.map((item) => {
|
||||||
<nav aria-label="ลิ้งค์โซเชียลมีเดีย" className="flex flex-col gap-3">
|
|
||||||
{currentLinks.map((item, index) => {
|
|
||||||
const IconComponent = iconMap[item.icon];
|
const IconComponent = iconMap[item.icon];
|
||||||
const isDonate = item.icon === "donate";
|
|
||||||
|
|
||||||
const count = getCountForLink(item.name, counts);
|
const count = getCountForLink(item.name, counts);
|
||||||
|
const external = !item.link.startsWith("/");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
key={index}
|
key={item.link}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="w-full h-12 p-4 group md:bg-muted bg-black/60 "
|
className="group h-12 w-full bg-black/60 p-4 transition-colors hover:border-primary/50 hover:bg-accent/80 md:bg-muted"
|
||||||
asChild
|
asChild
|
||||||
>
|
>
|
||||||
<Link href={item.link} target={item.link.startsWith("/") ? undefined : "_blank"} rel={item.link.startsWith("/") ? undefined : "noopener noreferrer"} >
|
<Link
|
||||||
<div className="flex items-center justify-between w-full">
|
href={item.link}
|
||||||
<div className="flex items-center gap-3">
|
target={external ? "_blank" : undefined}
|
||||||
<div className="shrink-0 w-8 h-8 flex items-center justify-center">
|
rel={external ? "noopener noreferrer" : undefined}
|
||||||
<IconComponent className="w-6 h-6 text-zinc-300" />
|
>
|
||||||
</div>
|
<span className="flex w-full items-center justify-between gap-3">
|
||||||
<div className="flex flex-col items-start text-left">
|
<span className="flex min-w-0 items-center gap-3">
|
||||||
<span className="font-medium text-zinc-100">{item.name}</span>
|
<span className="flex size-8 shrink-0 items-center justify-center">
|
||||||
{item.desc && <span className="text-xs text-zinc-400">{item.desc}</span>}
|
<IconComponent className="size-6 text-muted-foreground transition-colors group-hover:text-foreground" />
|
||||||
</div>
|
</span>
|
||||||
</div>
|
<span className="flex min-w-0 flex-col items-start text-left">
|
||||||
{isDonate ? (
|
<span className="truncate font-medium text-foreground">
|
||||||
<span className="text-xs font-medium shrink-0 text-zinc-400">ขี้นจอ 10 บาท+</span>
|
{item.name}
|
||||||
) : count !== null && (
|
</span>
|
||||||
<span className="text-xs font-medium shrink-0">
|
{item.desc && (
|
||||||
{formatCount(count.count)}
|
<span className="truncate text-xs text-muted-foreground">
|
||||||
<span className="text-zinc-400"> {count.label}</span>
|
{item.desc}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</span>
|
||||||
|
</span>
|
||||||
|
{item.icon === "donate" ? (
|
||||||
|
<span className="shrink-0 text-xs font-medium text-muted-foreground">
|
||||||
|
ขึ้นจอ 10 บาท+
|
||||||
|
</span>
|
||||||
|
) : count !== null ? (
|
||||||
|
<span className="shrink-0 text-xs font-medium">
|
||||||
|
{formatCount(count.count)}{" "}
|
||||||
|
<span className="text-muted-foreground">{count.label}</span>
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</span>
|
||||||
</Link>
|
</Link>
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
);
|
||||||
<div className="flex justify-between items-center pt-4">
|
}
|
||||||
<Button
|
|
||||||
variant="ghost"
|
export function LinkCard({ counts, links1, links2 }: { counts: FollowerCounts; links1: readonly LinkConfig[]; links2: readonly LinkConfig[] }) {
|
||||||
onClick={() => setIsPage2(false)}
|
return (
|
||||||
disabled={!isPage2}
|
<LinkCarousel
|
||||||
aria-label="หน้าก่อนหน้า"
|
primary={<LinkList counts={counts} label="ลิงก์หลัก" links={links1} />}
|
||||||
>
|
secondary={<LinkList counts={counts} label="ลิงก์เพิ่มเติม" links={links2} />}
|
||||||
<ArrowLeft />
|
/>
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
onClick={() => setIsPage2(true)}
|
|
||||||
disabled={isPage2}
|
|
||||||
aria-label="หน้าถัดไป"
|
|
||||||
>
|
|
||||||
<ArrowRight />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useState, type ReactNode } from "react";
|
||||||
|
import { ArrowLeft, ArrowRight } from "lucide-react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { CardContent } from "@/components/ui/card";
|
||||||
|
|
||||||
|
export function LinkCarousel({
|
||||||
|
primary,
|
||||||
|
secondary,
|
||||||
|
}: {
|
||||||
|
primary: ReactNode;
|
||||||
|
secondary: ReactNode;
|
||||||
|
}) {
|
||||||
|
const [page, setPage] = useState<0 | 1>(0);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<CardContent>
|
||||||
|
<div
|
||||||
|
key={page}
|
||||||
|
className="animate-in fade-in slide-in-from-bottom-2 duration-150"
|
||||||
|
>
|
||||||
|
{page === 0 ? primary : secondary}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center justify-between gap-3 pt-4">
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => setPage(0)}
|
||||||
|
disabled={page === 0}
|
||||||
|
aria-label="หน้าก่อนหน้า"
|
||||||
|
>
|
||||||
|
<ArrowLeft />
|
||||||
|
</Button>
|
||||||
|
<span
|
||||||
|
className="text-xs font-medium text-muted-foreground"
|
||||||
|
aria-live="polite"
|
||||||
|
>
|
||||||
|
{page + 1} / 2
|
||||||
|
</span>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
onClick={() => setPage(1)}
|
||||||
|
disabled={page === 1}
|
||||||
|
aria-label="หน้าถัดไป"
|
||||||
|
>
|
||||||
|
<ArrowRight />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user