Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
feat(insights): show layout-shaped skeletons while Insights loads (#2202)
void03bece15aebb
diff --git a/src/components/InsightsView.tsx b/src/components/InsightsView.tsxindex 6cdedd7b7..94af965f1 100644--- a/src/components/InsightsView.tsx+++ b/src/components/InsightsView.tsx@@ -1,5 +1,5 @@import { lazy, Suspense, useCallback, useEffect, useMemo, useRef, useState } from "react";-import { BarChart3, Cloud, CloudUpload, Flame, Gauge, Loader2, Mic2, Trophy } from "./icons";+import { BarChart3, Cloud, CloudUpload, Flame, Gauge, Mic2, Trophy } from "./icons";import { useTranslation } from "react-i18next";import { useAuth } from "../hooks/useAuth";import { useInsightsSyncOptIn } from "../hooks/useInsightsSyncOptIn";@@ -17,8 +17,10 @@ import { useLeaderboardParticipationStore } from "../stores/leaderboardParticipaimport { usePolicyStore } from "../stores/policyStore";import type { AnalyticsDailyBucket, AnalyticsSummary } from "../types/electron";import { cn } from "./lib/utils";+import LeaderboardSkeleton from "./LeaderboardSkeleton";import { Button } from "./ui/button";import { PAGE_CONTENT_WIDTH_CLASS } from "./ui/pageWidth";+import { Skeleton } from "./ui/skeleton";import { Tabs, TabsContent, TabsList, TabsTrigger } from "./ui/tabs";import { Tooltip } from "./ui/tooltip";@@ -43,10 +45,10 @@ function dateFromLocalKey(value: string) {return new Date(year, month - 1, day, 12);}-function Heatmap({ daily }: { daily: AnalyticsDailyBucket[] }) {+function Heatmap({ daily }: { daily: AnalyticsDailyBucket[] | null }) {const { t, i18n } = useTranslation();const calendar = useMemo(() => {- const days: ActivityDay[] = buildAnalyticsActivityDays(daily);+ const days: ActivityDay[] = buildAnalyticsActivityDays(daily ?? []);const cells: Array<ActivityDay | null> = [...Array(dateFromLocalKey(days[0].date).getDay()).fill(null),...days,@@ -127,7 +129,13 @@ function Heatmap({ daily }: { daily: AnalyticsDailyBucket[] }) {))}</div>- <div className="grid gap-2" style={columnStyle}>+ {/* Until the summary arrives every day reads as empty, so the cells pulse and+ stay inert: no "0 words" tooltip or label for a day that isn't counted yet. */}+ <div+ className={cn("grid gap-2", !daily && "animate-pulse")}+ style={columnStyle}+ inert={!daily}+ >{calendar.weeks.map((week, weekIndex) => (<div key={weekIndex} className="grid grid-rows-7 gap-0.5">{week.map((day, dayIndex) => {@@ -195,8 +203,9 @@ function MetricCard({}: {icon: typeof BarChart3;label: string;- value: string;- detail: string;+ // Null until the summary loads; the line holds a skeleton meanwhile.+ value: string | null;+ detail: string | null;largeValue?: boolean;}) {return (@@ -211,9 +220,13 @@ function MetricCard({largeValue ? "text-3xl" : "text-2xl")}>- {value}+ {value ?? (+ <Skeleton className={cn("inline-block w-20 align-middle", largeValue ? "h-7" : "h-6")} />+ )}+ </p>+ <p className="mt-1 text-[11px] text-muted-foreground/70">+ {detail ?? <Skeleton className="inline-block h-2.5 w-24 align-middle" />}</p>- <p className="mt-1 text-[11px] text-muted-foreground/70">{detail}</p></div>);}@@ -316,17 +329,6 @@ function YourUsage({);}- if (!summary) {- return (- <div className="rounded-lg border border-border bg-card/50 backdrop-blur-sm dark:bg-card/60">- <div className="flex items-center justify-center gap-2 py-8">- <Loader2 size={14} className="animate-spin text-primary" />- <span className="text-sm text-muted-foreground">{t("controlPanel.loading")}</span>- </div>- </div>- );- }-return (<>{!dataRetentionEnabled && (@@ -338,7 +340,7 @@ function YourUsage({</div>)}- {summary.totalDictations === 0 ? (+ {summary?.totalDictations === 0 ? (<div className="rounded-lg border border-border bg-card/50 backdrop-blur-sm dark:bg-card/60"><div className="flex flex-col items-center justify-center px-4 py-16 text-center"><BarChart3 size={40} className="mb-4 text-foreground/45" aria-hidden="true" />@@ -350,40 +352,47 @@ function YourUsage({</div>) : (<>+ {!summary && (+ <p role="status" className="sr-only">+ {t("controlPanel.loading")}+ </p>+ )}<div className="grid grid-cols-2 gap-3 lg:grid-cols-4"><MetricCardicon={Mic2}label={t("insights.wordsSpoken")}- value={number.format(summary.totalWords)}+ value={summary && number.format(summary.totalWords)}detail={t("insights.allTime")}largeValue/><MetricCardicon={Gauge}label={t("insights.wordsPerMinute")}- value={summary.averageWpm == null ? "—" : number.format(summary.averageWpm)}- detail={t("insights.wpmCoverage", { count: summary.wpmCoveragePercent })}+ value={+ summary && (summary.averageWpm == null ? "—" : number.format(summary.averageWpm))+ }+ detail={summary && t("insights.wpmCoverage", { count: summary.wpmCoveragePercent })}largeValue/><MetricCardicon={BarChart3}label={t("insights.dictations")}- value={number.format(summary.totalDictations)}+ value={summary && number.format(summary.totalDictations)}detail={t("insights.allTime")}largeValue/><MetricCardicon={Flame}label={t("insights.currentStreak")}- value={t("insights.days", { count: summary.currentStreakDays })}- detail={t("insights.longestStreak", { count: summary.longestStreakDays })}+ value={summary && t("insights.days", { count: summary.currentStreakDays })}+ detail={summary && t("insights.longestStreak", { count: summary.longestStreakDays })}/></div><div className="mt-5 rounded-2xl border border-border/70 bg-card/70 px-5 py-2.5 dark:border-white/10"><h2 className="text-base font-medium text-foreground">{t("insights.activity")}</h2><div className="mt-2">- <Heatmap daily={summary.daily} />+ <Heatmap daily={summary?.daily ?? null} /></div></div></>@@ -497,7 +506,7 @@ export default function InsightsView({ onSignIn }: InsightsViewProps) {)}</TabsContent><TabsContent value="leaderboard" className="mt-0">- <Suspense fallback={null}>+ <Suspense fallback={isSignedIn ? <LeaderboardSkeleton /> : null}><LeaderboardViewenableInsightsSync={enableInsightsSync}insightsSyncEnabled={insightsSyncEnabled}diff --git a/src/components/LeaderboardPodium.tsx b/src/components/LeaderboardPodium.tsxindex b721a4e1d..eb299e928 100644--- a/src/components/LeaderboardPodium.tsx+++ b/src/components/LeaderboardPodium.tsx@@ -1,7 +1,9 @@+import type { ReactNode } from "react";import { Crown, Medal } from "./icons";import type { LeaderboardMember } from "../types/electron";import { cn } from "./lib/utils";import MemberAvatar from "./MemberAvatar";+import { Skeleton } from "./ui/skeleton";const PODIUM_PLACEMENTS = [{@@ -27,24 +29,17 @@ const PODIUM_PLACEMENTS = [},] as const;-export default function LeaderboardPodium({- formatValue,- memberLabel,- members,- metricLabel,- periodLabel,+function PodiumFrame({+ children,+ detail,+ placeCount,title,}: {- formatValue: (member: LeaderboardMember) => string;- memberLabel: (member: LeaderboardMember) => string;- members: LeaderboardMember[];- metricLabel: string;- periodLabel: string;+ children: ReactNode;+ detail: ReactNode;+ placeCount: number;title: string;}) {- if (members.length === 0) return null;- const placements = PODIUM_PLACEMENTS.slice(0, Math.min(members.length, 3));-return (<div className="px-5 pb-5 pt-4"><div className="mb-4 flex flex-wrap items-center justify-between gap-2">@@ -52,60 +47,130 @@ export default function LeaderboardPodium({<Medal size={14} className="text-amber-500" />{title}</div>- <p className="text-[11px] text-muted-foreground">- {metricLabel} · {periodLabel}- </p>+ <p className="text-[11px] text-muted-foreground">{detail}</p></div><divclassName={cn("grid grid-cols-1 items-end gap-3",- members.length === 1 && "mx-auto max-w-md",- members.length === 2 && "mx-auto max-w-3xl sm:grid-cols-2",- members.length >= 3 && "sm:grid-cols-3"+ placeCount === 1 && "mx-auto max-w-md",+ placeCount === 2 && "mx-auto max-w-3xl sm:grid-cols-2",+ placeCount >= 3 && "sm:grid-cols-3")}>- {placements.map(({ memberIndex, cardClass, rankClass, iconClass, Icon }) => {- const member = members[memberIndex];- if (!member) return null;-- return (- <div- key={member.userId}- className={cn(- "relative flex min-h-36 flex-col items-center justify-center rounded-xl border px-4 py-4 text-center",- members.length >= 3 && member.rank === 1 && "sm:order-2",- members.length >= 3 && member.rank === 2 && "sm:order-1",- members.length >= 3 && member.rank === 3 && "sm:order-3",- cardClass- )}- >- <div- className={cn(- "absolute left-3 top-3 flex h-6 min-w-6 items-center justify-center gap-1 rounded-md px-1.5 text-[10px] font-semibold tabular-nums",- rankClass- )}- >- <Icon size={11} className={iconClass} />- {member.rank}- </div>+ {children}+ </div>+ </div>+ );+}- <div className="rounded-full ring-4 ring-background/70">- <MemberAvatar- name={member.name}- email={member.email}- image={member.image}- size="lg"- />- </div>- <p className="mt-3 max-w-full truncate text-sm font-medium">{memberLabel(member)}</p>- <p className="mt-1 text-2xl font-semibold tracking-tight tabular-nums">- {formatValue(member)}- </p>- </div>- );- })}+function PodiumPlace({+ children,+ placeCount,+ placement: { cardClass, rankClass, iconClass, Icon },+ rank,+}: {+ children: ReactNode;+ placeCount: number;+ placement: (typeof PODIUM_PLACEMENTS)[number];+ rank: number;+}) {+ return (+ <div+ className={cn(+ "relative flex min-h-36 flex-col items-center justify-center rounded-xl border px-4 py-4 text-center",+ placeCount >= 3 && rank === 1 && "sm:order-2",+ placeCount >= 3 && rank === 2 && "sm:order-1",+ placeCount >= 3 && rank === 3 && "sm:order-3",+ cardClass+ )}+ >+ <div+ className={cn(+ "absolute left-3 top-3 flex h-6 min-w-6 items-center justify-center gap-1 rounded-md px-1.5 text-[10px] font-semibold tabular-nums",+ rankClass+ )}+ >+ <Icon size={11} className={iconClass} />+ {rank}</div>+ {children}</div>);}++/** The podium's title and placements, with the members, metric and period still to come. */+export function LeaderboardPodiumSkeleton({ title }: { title: string }) {+ return (+ <PodiumFrame+ detail={<Skeleton className="inline-block h-2.5 w-28 align-middle" />}+ placeCount={PODIUM_PLACEMENTS.length}+ title={title}+ >+ {PODIUM_PLACEMENTS.map((placement) => (+ <PodiumPlace+ key={placement.memberIndex}+ placeCount={PODIUM_PLACEMENTS.length}+ placement={placement}+ rank={placement.memberIndex + 1}+ >+ <Skeleton className="size-11 rounded-full" />+ <p className="mt-3 text-sm font-medium">+ <Skeleton className="inline-block h-3.5 w-24 align-middle" />+ </p>+ <p className="mt-1 text-2xl font-semibold tracking-tight">+ <Skeleton className="inline-block h-6 w-16 align-middle" />+ </p>+ </PodiumPlace>+ ))}+ </PodiumFrame>+ );+}++export default function LeaderboardPodium({+ formatValue,+ memberLabel,+ members,+ metricLabel,+ periodLabel,+ title,+}: {+ formatValue: (member: LeaderboardMember) => string;+ memberLabel: (member: LeaderboardMember) => string;+ members: LeaderboardMember[];+ metricLabel: string;+ periodLabel: string;+ title: string;+}) {+ if (members.length === 0) return null;+ const placeCount = Math.min(members.length, PODIUM_PLACEMENTS.length);++ return (+ <PodiumFrame detail={`${metricLabel} · ${periodLabel}`} placeCount={placeCount} title={title}>+ {PODIUM_PLACEMENTS.slice(0, placeCount).map((placement) => {+ const member = members[placement.memberIndex];+ return (+ <PodiumPlace+ key={member.userId}+ placeCount={placeCount}+ placement={placement}+ rank={member.rank}+ >+ <div className="rounded-full ring-4 ring-background/70">+ <MemberAvatar+ name={member.name}+ email={member.email}+ image={member.image}+ size="lg"+ />+ </div>+ <p className="mt-3 max-w-full truncate text-sm font-medium">{memberLabel(member)}</p>+ <p className="mt-1 text-2xl font-semibold tracking-tight tabular-nums">+ {formatValue(member)}+ </p>+ </PodiumPlace>+ );+ })}+ </PodiumFrame>+ );+}diff --git a/src/components/LeaderboardSection.tsx b/src/components/LeaderboardSection.tsxindex 75d982bd6..4f0476b61 100644--- a/src/components/LeaderboardSection.tsx+++ b/src/components/LeaderboardSection.tsx@@ -7,7 +7,6 @@ import {ChevronRight,Clock3,Globe2,- Loader2,LocateFixed,LogOut,MoreHorizontal,@@ -63,6 +62,7 @@ import LeaderboardPodium from "./LeaderboardPodium";import LeaderboardSetupCard from "./LeaderboardSetupCard";import LeaderboardShareDialog from "./LeaderboardShareDialog";import LeaderboardSignInPreview from "./LeaderboardSignInPreview";+import LeaderboardSkeleton, { LeaderboardBoardSkeleton } from "./LeaderboardSkeleton";import LeaderboardSoloEmptyState from "./LeaderboardSoloEmptyState";import LeaderboardWorkspaceNudge from "./LeaderboardWorkspaceNudge";import LeaderboardJoinPreview from "./LeaderboardJoinPreview";@@ -76,6 +76,7 @@ import {} from "./ui/dropdown-menu";import { Input } from "./ui/input";import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select";+import { Skeleton } from "./ui/skeleton";import { Tooltip } from "./ui/tooltip";import { useToast } from "./ui/useToast";@@ -642,13 +643,7 @@ export default function LeaderboardSection({const funnelCardClassName = funnelScopeSelect ? "mt-4" : "mt-6";if (!isSignedIn) return <LeaderboardSignInPreview className="mt-6" onSignIn={onSignIn} />;- if (accessLoading && !access) {- return (- <section className="mt-6 flex min-h-48 items-center justify-center rounded-2xl border border-border/70 bg-card/70 text-muted-foreground dark:border-white/10">- <Loader2 size={18} className="animate-spin" />- </section>- );- }+ if (accessLoading && !access) return <LeaderboardSkeleton />;if (accessError && !access) {return (<LeaderboardRetryCard@@ -726,13 +721,7 @@ export default function LeaderboardSection({/>);}- if (surface === "participation_loading") {- return (- <section className="mt-6 flex min-h-48 items-center justify-center rounded-2xl border border-border/70 bg-card/70 text-muted-foreground dark:border-white/10">- <Loader2 size={18} className="animate-spin" />- </section>- );- }+ if (surface === "participation_loading") return <LeaderboardSkeleton />;if (surface === "join") {return (<LeaderboardJoinPreview@@ -840,6 +829,9 @@ export default function LeaderboardSection({workspaceName={access.joinableWorkspace.name}/>) : null;+ // While the body below shows its skeleton, the header holds the member count+ // and period picker a loaded board adds.+ const boardLoading = !visibleLeaderboard && !visibleFailure && !isSoloScope && cloudAccessAllowed;return (<section@@ -866,12 +858,16 @@ export default function LeaderboardSection({<h2 className="truncate text-sm font-semibold">{selectedScope.name}</h2>)}<div className="mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-[11px] text-muted-foreground">- {boardParticipantCount != null && (+ {(boardParticipantCount != null || boardLoading) && (<>- <span className="flex items-center gap-1">- <Users size={11} />- {t("workspaces.join.memberCount", { count: boardParticipantCount })}- </span>+ {boardParticipantCount != null ? (+ <span className="flex items-center gap-1">+ <Users size={11} />+ {t("workspaces.join.memberCount", { count: boardParticipantCount })}+ </span>+ ) : (+ <Skeleton className="h-2.5 w-18" />+ )}<spanaria-hidden="true"className="size-0.5 rounded-full bg-muted-foreground/50"@@ -886,7 +882,7 @@ export default function LeaderboardSection({</div></div><div className="flex items-center gap-2">- {visibleLeaderboard && (+ {visibleLeaderboard ? (<Selectvalue={range === "all" ? "all" : activeWeekStart}onValueChange={(value) => {@@ -919,6 +915,8 @@ export default function LeaderboardSection({))}</SelectContent></Select>+ ) : (+ boardLoading && <Skeleton className="h-8 w-44 rounded-lg" />)}<DropdownMenu><DropdownMenuTrigger asChild>@@ -1014,9 +1012,7 @@ export default function LeaderboardSection({}/>) : !visibleLeaderboard ? (- <div className="flex min-h-48 items-center justify-center text-muted-foreground">- <Loader2 size={18} className="animate-spin" />- </div>+ <LeaderboardBoardSkeleton />) : (<divaria-busy={leaderboardStale}diff --git a/src/components/LeaderboardSkeleton.tsx b/src/components/LeaderboardSkeleton.tsxnew file mode 100644index 000000000..896d04b5b--- /dev/null+++ b/src/components/LeaderboardSkeleton.tsx@@ -0,0 +1,101 @@+import { useTranslation } from "react-i18next";+import { Clock3 } from "./icons";+import { cn } from "./lib/utils";+import { LeaderboardPodiumSkeleton } from "./LeaderboardPodium";+import { Skeleton } from "./ui/skeleton";++const ROW_WIDTHS = [+ ["w-32", "w-44"],+ ["w-24", "w-36"],+ ["w-36", "w-48"],+ ["w-28", "w-40"],+ ["w-40", "w-44"],+] as const;++/** The podium and ranked rows, for a board whose header is already on screen. */+export function LeaderboardBoardSkeleton() {+ const { t } = useTranslation();+ return (+ <>+ <span role="status" className="sr-only">+ {t("controlPanel.loading")}+ </span>+ <LeaderboardPodiumSkeleton title={t("insights.leaderboard.topPerformers")} />++ <div className="overflow-x-auto">+ <table className="w-full min-w-[560px] text-sm">+ <thead className="bg-muted/10">+ <tr className="border-y border-border/70 text-start text-[11px] uppercase tracking-wide text-muted-foreground">+ <th scope="col" className="w-16 px-5 py-2.5 font-medium">+ {t("insights.leaderboard.rank")}+ </th>+ <th scope="col" className="px-3 py-2.5 font-medium">+ {t("insights.leaderboard.member")}+ </th>+ <th scope="col" className="w-56 px-5 py-2 font-medium">+ <Skeleton className="ml-auto h-8 w-48 rounded-lg" />+ </th>+ </tr>+ </thead>+ <tbody>+ {ROW_WIDTHS.map(([nameWidth, detailWidth]) => (+ <tr key={nameWidth} className="border-b border-border/70 last:border-0">+ <td className="px-5 py-3">+ <Skeleton className="size-6" />+ </td>+ <td className="px-3 py-3">+ <div className="flex items-center gap-2.5">+ <Skeleton className="size-5 shrink-0 rounded-full" />+ <div>+ <p>+ <Skeleton className={cn("inline-block h-3.5 align-middle", nameWidth)} />+ </p>+ <p className="text-[11px]">+ <Skeleton className={cn("inline-block h-2.5 align-middle", detailWidth)} />+ </p>+ </div>+ </div>+ </td>+ <td className="px-5 py-3">+ <Skeleton className="ml-auto h-3.5 w-12" />+ </td>+ </tr>+ ))}+ </tbody>+ </table>+ </div>+ </>+ );+}++/** A whole leaderboard card, for while the board it will show is still unknown. */+export default function LeaderboardSkeleton() {+ const { t } = useTranslation();+ return (+ <section className="mt-6 overflow-hidden rounded-2xl border border-border/70 bg-card/70 dark:border-white/10">+ <div className="flex flex-wrap items-center justify-between gap-4 border-b border-border/70 px-5 py-4">+ <div className="flex min-w-0 items-center gap-3">+ <Skeleton className="size-9 shrink-0 rounded-lg" />+ <div className="min-w-0">+ <p className="text-sm font-semibold">+ <Skeleton className="inline-block h-3.5 w-36 align-middle" />+ </p>+ <div className="mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-[11px] text-muted-foreground">+ <Skeleton className="h-2.5 w-18" />+ <span aria-hidden="true" className="size-0.5 rounded-full bg-muted-foreground/50" />+ <span className="flex items-center gap-1">+ <Clock3 size={11} />+ {t("insights.leaderboard.refreshCadence")}+ </span>+ </div>+ </div>+ </div>+ <div className="flex items-center gap-2">+ <Skeleton className="h-8 w-44 rounded-lg" />+ <Skeleton className="size-8" />+ </div>+ </div>+ <LeaderboardBoardSkeleton />+ </section>+ );+}diff --git a/src/components/ui/skeleton.tsx b/src/components/ui/skeleton.tsxindex 098e5540c..8fd77cea7 100644--- a/src/components/ui/skeleton.tsx+++ b/src/components/ui/skeleton.tsx@@ -1,7 +1,10 @@import { cn } from "../lib/utils";-function Skeleton({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {- return <div className={cn("animate-pulse rounded-md bg-muted", className)} {...props} />;+// A span, so it can sit inside a <p>; add inline-block to keep that line's height.+function Skeleton({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>) {+ return (+ <span className={cn("block animate-pulse rounded-md bg-foreground/6", className)} {...props} />+ );}export { Skeleton };diff --git a/test/components/leaderboardStates.test.js b/test/components/leaderboardStates.test.jsindex 6fedbf17c..3b873174c 100644--- a/test/components/leaderboardStates.test.js+++ b/test/components/leaderboardStates.test.js@@ -199,3 +199,16 @@ test("podium cards accent all three placements", async () => {assert.ok(markup.includes("border-slate-400/30 bg-slate-400/5"));assert.ok(markup.includes("border-orange-500/25 bg-orange-500/5"));});++test("the loading board shows its fixed copy, with placeholders only for the data", async () => {+ const LoadingBoard = await component("LeaderboardSkeleton");+ const markup = renderToStaticMarkup(createElement(LoadingBoard));++ for (const copy of ["Updates hourly", "Top performers", "Rank", "Member", "Loading..."]) {+ assert.ok(markup.includes(copy), `expected the loading board to show “${copy}”`);+ }+ assert.ok(markup.includes("border-amber-400/25 bg-amber-400/5"));+ assert.ok(markup.includes("border-slate-400/30 bg-slate-400/5"));+ assert.ok(markup.includes("border-orange-500/25 bg-orange-500/5"));+ assert.match(markup, /role="status"[^>]*>Loading\.\.\.</, "only the message is announced");+});