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.

Add some loading states

Tim Wilson2ad67be1a1a3
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/overview-chart.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/overview-chart.tsx
index e1df57af06..078d5a6d0e 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/overview-chart.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/programs/[programId]/overview-chart.tsx
@@ -3,6 +3,7 @@ import { ChartContext } from "@/ui/charts/chart-context";
import TimeSeriesChart from "@/ui/charts/time-series-chart";
import XAxis from "@/ui/charts/x-axis";
import YAxis from "@/ui/charts/y-axis";
+import { LoadingSpinner } from "@dub/ui/src/icons";
import { currencyFormatter } from "@dub/utils";
import { LinearGradient } from "@visx/gradient";
import { subDays } from "date-fns";
@@ -27,57 +28,69 @@ export function OverviewChart() {
const totalError = null;
const dataLoading = !data && !dataError;
- const totalLoading = false;
+ const totalLoading = total === undefined && !totalError;
return (
<div>
<div className="flex flex-col gap-1 p-2">
<span className="text-sm text-neutral-500">Revenue</span>
- <span className="text-3xl text-neutral-800">
- {currencyFormatter(total / 100, {
- minimumFractionDigits: 2,
- maximumFractionDigits: 2,
- })}
- </span>
+ {totalLoading ? (
+ <div className="h-9 w-24 animate-pulse rounded-md bg-neutral-200" />
+ ) : (
+ <span className="text-3xl text-neutral-800">
+ {totalError
+ ? "-"
+ : currencyFormatter(total / 100, {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ })}
+ </span>
+ )}
</div>
<div className="relative mt-4 h-72 md:h-96">
- <TimeSeriesChart
- data={data}
- series={[
- {
- id: "earnings",
- valueAccessor: (d) => d.values.earnings / 100,
- colorClassName: "text-[#8B5CF6]",
- isActive: true,
- },
- ]}
- >
- <ChartContext.Consumer>
- {(context) => (
- <LinearGradient
- id={`${id}-color-gradient`}
- from="#8B5CF6"
- to="#4C1D95"
- x1={0}
- x2={context?.width ?? 1}
- gradientUnits="userSpaceOnUse"
- />
- )}
- </ChartContext.Consumer>
-
- <XAxis />
- <YAxis showGridLines />
- <Areas
- seriesStyles={[
+ {dataLoading ? (
+ <div className="flex size-full items-center justify-center">
+ <LoadingSpinner />
+ </div>
+ ) : (
+ <TimeSeriesChart
+ data={data}
+ series={[
{
id: "earnings",
- areaFill: `url(#${id}-color-gradient)`,
- lineStroke: `url(#${id}-color-gradient)`,
- lineClassName: "text-violet-500",
+ valueAccessor: (d) => d.values.earnings / 100,
+ colorClassName: "text-[#8B5CF6]",
+ isActive: true,
},
]}
- />
- </TimeSeriesChart>
+ >
+ <ChartContext.Consumer>
+ {(context) => (
+ <LinearGradient
+ id={`${id}-color-gradient`}
+ from="#8B5CF6"
+ to="#4C1D95"
+ x1={0}
+ x2={context?.width ?? 1}
+ gradientUnits="userSpaceOnUse"
+ />
+ )}
+ </ChartContext.Consumer>
+
+ <XAxis />
+ <YAxis showGridLines />
+ <Areas
+ seriesStyles={[
+ {
+ id: "earnings",
+ areaFill: `url(#${id}-color-gradient)`,
+ lineStroke: `url(#${id}-color-gradient)`,
+ lineClassName: "text-violet-500",
+ },
+ ]}
+ />
+ </TimeSeriesChart>
+ )}
</div>
</div>
);