Skip to content

Commit 935b947

Browse files
committed
Add a progress indicator while the coaching notes are loading.
1 parent 7cdb296 commit 935b947

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed

package-lock.json

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@radix-ui/react-label": "^2.1.1",
2222
"@radix-ui/react-navigation-menu": "^1.2.3",
2323
"@radix-ui/react-popover": "^1.1.4",
24+
"@radix-ui/react-progress": "^1.1.7",
2425
"@radix-ui/react-scroll-area": "^1.2.2",
2526
"@radix-ui/react-select": "^2.1.4",
2627
"@radix-ui/react-separator": "^1.1.2",

src/components/ui/coaching-sessions/coaching-notes.tsx

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useCollaborationToken } from "@/lib/api/collaboration-token";
88
import { useAuthStore } from "@/lib/providers/auth-store-provider";
99
import { useCoachingSessionStateStore } from "@/lib/providers/coaching-session-state-store-provider";
1010
import { Extensions } from "@/components/ui/coaching-sessions/coaching-notes/extensions";
11+
import { Progress } from "@/components/ui/progress";
1112
import { Toolbar } from "@/components/ui/coaching-sessions/coaching-notes/toolbar";
1213
import { siteConfig } from "@/site.config";
1314
import "@/styles/styles.scss";
@@ -91,15 +92,55 @@ const useCollaborationProvider = (doc: Y.Doc) => {
9192

9293
const CoachingNotes = () => {
9394
const [doc] = useState(() => new Y.Doc());
95+
const [loadingProgress, setLoadingProgress] = useState(0);
9496
const { isLoading, isError, extensions } = useCollaborationProvider(doc);
9597

96-
if (isLoading) return <div>Loading coaching notes...</div>;
97-
if (isError)
98+
// Simulate loading progress
99+
useEffect(() => {
100+
if (isLoading) {
101+
setLoadingProgress(0);
102+
const interval = setInterval(() => {
103+
setLoadingProgress((prev) => {
104+
if (prev >= 90) {
105+
clearInterval(interval);
106+
return 90; // Stop at 90% until actually loaded
107+
}
108+
return prev + Math.random() * 15;
109+
});
110+
}, 200);
111+
112+
return () => clearInterval(interval);
113+
} else {
114+
// Complete the progress (100%) when loading is done
115+
setLoadingProgress(100);
116+
}
117+
}, [isLoading]);
118+
119+
if (isLoading) {
120+
return (
121+
<div className="flex flex-col items-center justify-center space-y-4 p-8 min-h-[440px] lg:min-h-[440px] sm:min-h-[200px] md:min-h-[350px]">
122+
<div className="w-full max-w-md">
123+
<div className="flex items-center justify-between mb-2">
124+
<span className="text-sm font-medium text-gray-700 dark:text-gray-300">
125+
Loading coaching notes...
126+
</span>
127+
<span className="text-sm text-gray-500 dark:text-gray-400">
128+
{Math.round(loadingProgress)}%
129+
</span>
130+
</div>
131+
<Progress value={loadingProgress} className="h-2" />
132+
</div>
133+
</div>
134+
);
135+
}
136+
137+
if (isError) {
98138
return (
99139
<div>
100140
We could not retrieve your coaching notes. Please try again later.
101141
</div>
102142
);
143+
}
103144

104145
return (
105146
<div className="border rounded">

src/components/ui/progress.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use client";
2+
3+
import * as React from "react";
4+
import * as ProgressPrimitive from "@radix-ui/react-progress";
5+
6+
import { cn } from "@/components/lib/utils";
7+
8+
const Progress = React.forwardRef<
9+
React.ElementRef<typeof ProgressPrimitive.Root>,
10+
React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root>
11+
>(({ className, value, ...props }, ref) => (
12+
<ProgressPrimitive.Root
13+
ref={ref}
14+
className={cn(
15+
"relative h-4 w-full overflow-hidden rounded-full bg-secondary",
16+
className
17+
)}
18+
{...props}
19+
>
20+
<ProgressPrimitive.Indicator
21+
className="h-full w-full flex-1 bg-primary transition-all"
22+
style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
23+
/>
24+
</ProgressPrimitive.Root>
25+
));
26+
Progress.displayName = ProgressPrimitive.Root.displayName;
27+
28+
export { Progress };

0 commit comments

Comments
 (0)