🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Refactor FunnelRow and RetentionPage components to enhance loading states
Bill Yange5dbb6372bcc
diff --git a/client/src/app/[site]/funnels/components/FunnelRow.tsx b/client/src/app/[site]/funnels/components/FunnelRow.tsxindex 6e3ba30da..8b78d6540 100644--- a/client/src/app/[site]/funnels/components/FunnelRow.tsx+++ b/client/src/app/[site]/funnels/components/FunnelRow.tsx@@ -37,6 +37,7 @@ import {} from "../../components/shared/Filters/utils";import { EditFunnelDialog } from "./EditFunnel";import { Funnel } from "./Funnel";+import { ThreeDotLoader } from "../../../../components/Loaders";interface FunnelRowProps {funnel: SavedFunnel;@@ -230,13 +231,7 @@ export function FunnelRow({ funnel }: FunnelRowProps) {<div className="border-t border-neutral-200 dark:border-neutral-800"><div className="p-4">{isPending ? (- <div className="flex justify-center items-center h-[400px]">- <div className="animate-pulse flex items-center">- <div className="h-2 w-2 bg-neutral-500 rounded-full mr-1 animate-bounce"></div>- <div className="h-2 w-2 bg-neutral-500 rounded-full mr-1 animate-bounce [animation-delay:0.2s]"></div>- <div className="h-2 w-2 bg-neutral-500 rounded-full animate-bounce [animation-delay:0.4s]"></div>- </div>- </div>+ <ThreeDotLoader className="h-[400px]" />) : isError ? (<div className="text-red-500 p-4 text-center">Error loading funnel:{" "}diff --git a/client/src/app/[site]/retention/page.tsx b/client/src/app/[site]/retention/page.tsxindex 59b9d4df9..366c8a902 100644--- a/client/src/app/[site]/retention/page.tsx+++ b/client/src/app/[site]/retention/page.tsx@@ -30,6 +30,7 @@ import {import { HelpCircle } from "lucide-react";import { Skeleton } from "../../../components/ui/skeleton";import { RetentionChart } from "./RetentionChart";+import { ThreeDotLoader } from "../../../components/Loaders";// Available time range options (in days)const RANGE_OPTIONS = [@@ -84,66 +85,6 @@ const getRetentionColor = (};};-// Loading skeleton for the retention grid-const RetentionGridSkeleton = () => {- const periodHeaders = Array.from(- { length: DEFAULT_SKELETON_PERIODS + 1 },- (_, i) => (i === 0 ? "Cohort" : `Week ${i - 1}`)- );-- return (- <div className="overflow-x-auto">- <div- className="inline-grid gap-px bg-neutral-900 border border-neutral-800 rounded-lg shadow-lg"- style={{- gridTemplateColumns: `minmax(120px, auto) repeat(${DEFAULT_SKELETON_PERIODS}, minmax(90px, auto))`,- }}- >- {/* Header Row */}- {periodHeaders.map((header, i) => (- <div- key={`header-${i}`}- className={`p-3 font-semibold bg-neutral-900 text-center border-b border-neutral-700 ${- i === 0 ? "sticky left-0 z-10 border-r" : ""- }`}- >- <Skeleton className="h-4 w-16 mx-auto bg-neutral-700/50 animate-pulse" />- </div>- ))}-- {/* Data Rows */}- {Array.from({ length: DEFAULT_SKELETON_COHORTS }).map((_, rowIndex) => (- <Fragment key={`row-${rowIndex}`}>- {/* Cohort Info Cell */}- <div className="p-3 bg-neutral-900 text-sm sticky left-0 z-10 border-r border-neutral-700">- <Skeleton className="h-4 w-24 mb-2 bg-neutral-700/50 animate-pulse" />- <Skeleton className="h-3 w-16 bg-neutral-700/50 animate-pulse" />- </div>- {/* Retention Cells */}- {Array.from({ length: DEFAULT_SKELETON_PERIODS }).map(- (_, cellIndex) => (- <div- key={`cell-${rowIndex}-${cellIndex}`}- className="m-[2px] p-3 flex items-center justify-center bg-neutral-800 rounded-md"- >- <Skeleton- className={`h-4 w-10 bg-neutral-700/50 animate-pulse`}- style={{- animationDelay: `${- (rowIndex * DEFAULT_SKELETON_PERIODS + cellIndex) * 50- }ms`,- }}- />- </div>- )- )}- </Fragment>- ))}- </div>- </div>- );-};-export default function RetentionPage() {// State for the retention mode (day or week)const [mode, setMode] = useState<RetentionMode>("week");@@ -317,19 +258,13 @@ export default function RetentionPage() {</CardHeader><CardContent className="space-y-6">{/* Retention Chart */}- {isLoading ? (- <div className="h-[400px]">- <div className="w-full h-full space-y-3">- <Skeleton className="h-[350px] w-full bg-neutral-900 rounded-md animate-pulse" />- </div>- </div>- ) : data ? (+ {isLoading ? null : data ? (<RetentionChart data={data} isLoading={false} mode={mode} />) : null}<div>{isLoading ? (- <RetentionGridSkeleton />+ <ThreeDotLoader />) : data ? (<div className="overflow-x-auto"><divdiff --git a/client/src/components/Loaders.tsx b/client/src/components/Loaders.tsxnew file mode 100644index 000000000..e6a8fe0fa--- /dev/null+++ b/client/src/components/Loaders.tsx@@ -0,0 +1,15 @@+import { cn } from "../lib/utils";++export function ThreeDotLoader({ className }: { className?: string }) {+ return (+ <div+ className={cn("flex justify-center items-center h-[500px]", className)}+ >+ <div className="animate-pulse flex items-center">+ <div className="h-2 w-2 bg-neutral-500 rounded-full mr-1 animate-bounce"></div>+ <div className="h-2 w-2 bg-neutral-500 rounded-full mr-1 animate-bounce [animation-delay:0.2s]"></div>+ <div className="h-2 w-2 bg-neutral-500 rounded-full animate-bounce [animation-delay:0.4s]"></div>+ </div>+ </div>+ );+}