Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

improve animations

Steven Teyb34f46cf3845
diff --git a/apps/web/app/app.dub.co/(onboarding)/[slug]/wrapped/[year]/client.tsx b/apps/web/app/app.dub.co/(onboarding)/[slug]/wrapped/[year]/client.tsx
index f35ebd1390..1225fe1b9e 100644
--- a/apps/web/app/app.dub.co/(onboarding)/[slug]/wrapped/[year]/client.tsx
+++ b/apps/web/app/app.dub.co/(onboarding)/[slug]/wrapped/[year]/client.tsx
@@ -1,9 +1,9 @@
"use client";
import useWorkspace from "@/lib/swr/use-workspace";
-import LayoutLoader from "@/ui/layout/layout-loader";
import { BlurImage, ExpandingArrow } from "@dub/ui";
import {
+ cn,
DICEBEAR_AVATAR_URL,
smartTruncate,
STAGGER_CHILD_VARIANTS,
@@ -25,9 +25,12 @@ export default function WrappedPageClient() {
"Total Clicks": totalClicks,
};
- if (loading) {
- return <LayoutLoader />;
- } else if (!yearInReview) {
+ const placeholderArray = Array.from({ length: 5 }, (_, index) => ({
+ item: "placeholder",
+ count: 0,
+ }));
+
+ if (!loading && !yearInReview) {
redirect(`/${slug}`);
}
@@ -50,28 +53,45 @@ export default function WrappedPageClient() {
backgroundPosition: "center",
}}
>
- <BlurImage
- src={logo || `${DICEBEAR_AVATAR_URL}${name}`}
- alt={name || "Workspace Logo"}
- className="h-8 rounded-lg"
- width={32}
- height={32}
- />
- <h2 className="mt-1 text-xl font-semibold">{name}</h2>
+ {name ? (
+ <>
+ <BlurImage
+ src={logo || `${DICEBEAR_AVATAR_URL}${name}`}
+ alt={name || "Workspace Logo"}
+ className="h-8 rounded-full"
+ width={32}
+ height={32}
+ />
+ <h2 className="mt-1 text-xl font-semibold">{name}</h2>
+ </>
+ ) : (
+ <>
+ <div className="h-8 animate-pulse rounded-full bg-neutral-200" />
+ <div className="h-5 w-12 animate-pulse rounded-md bg-neutral-200" />
+ </>
+ )}
</div>
<div className="grid w-full grid-cols-2 gap-2 p-4">
{Object.entries(stats).map(([key, value]) => (
- <StatCard key={key} title={key} value={value || 0} />
+ <StatCard key={key} title={key} value={value} />
))}
</div>
<div className="grid gap-2 p-4">
<StatTable
title="Top Links"
- value={topLinks as { item: string; count: number }[]}
+ value={
+ topLinks
+ ? (topLinks as { item: string; count: number }[])
+ : placeholderArray
+ }
/>
<StatTable
title="Top Countries"
- value={topCountries as { item: string; count: number }[]}
+ value={
+ topCountries
+ ? (topCountries as { item: string; count: number }[])
+ : placeholderArray
+ }
/>
</div>
</div>
@@ -79,11 +99,23 @@ export default function WrappedPageClient() {
);
}
-const StatCard = ({ title, value }: { title: string; value: number }) => {
+const StatCard = ({
+ title,
+ value,
+}: {
+ title: string;
+ value: number | undefined;
+}) => {
return (
<div className="text-center">
<h3 className="font-medium text-neutral-500">{title}</h3>
- <NumberFlow value={value} className="text-lg font-medium text-black" />
+ <NumberFlow
+ value={value || 0}
+ className={cn(
+ "text-lg font-medium text-black",
+ value === undefined && "text-neutral-300",
+ )}
+ />
</div>
);
};
@@ -136,26 +168,33 @@ const StatTable = ({
key={index}
className="group flex justify-between py-1.5"
>
- <div className="flex items-center gap-2">
- {title === "Top Countries" && (
- <img
- src={`https://hatscripts.github.io/circle-flags/flags/${item.toLowerCase()}.svg`}
- alt={COUNTRIES[item]}
- className="size-4"
- />
- )}
- <div className="flex gap-0.5">
- <p className="font-medium text-black">
- {title === "Top Links"
- ? smartTruncate(item, 33)
- : COUNTRIES[item]}{" "}
- </p>
- <ExpandingArrow className="size-3" />
+ {item === "placeholder" ? (
+ <div className="h-4 w-12 animate-pulse rounded-md bg-neutral-200" />
+ ) : (
+ <div className="flex items-center gap-2">
+ {title === "Top Countries" && (
+ <img
+ src={`https://hatscripts.github.io/circle-flags/flags/${item.toLowerCase()}.svg`}
+ alt={COUNTRIES[item]}
+ className="size-4"
+ />
+ )}
+ <div className="flex gap-0.5">
+ <p className="font-medium text-black">
+ {title === "Top Links"
+ ? smartTruncate(item, 33)
+ : COUNTRIES[item]}{" "}
+ </p>
+ <ExpandingArrow className="size-3" />
+ </div>
</div>
- </div>
+ )}
<NumberFlow
value={count}
- className="text-neutral-600 group-hover:text-black"
+ className={cn(
+ "text-neutral-600 group-hover:text-black",
+ count === 0 && "text-neutral-300",
+ )}
/>
</a>
</motion.div>