diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx
index d9a33a2..b80d897 100644
--- a/src/app/dashboard/page.tsx
+++ b/src/app/dashboard/page.tsx
@@ -10,13 +10,19 @@ import { AdaptiveStudyPlan } from "@/components/AI/AdaptiveStudyPlan"
import { useActiveUser } from "@/hooks/useActiveUser"
export default function DashboardPage() {
- const { user, hasAccessTo, loading } = useActiveUser()
- const progressRef = useRef(null)
+ const { user, userId, loading: userLoading, hasAccessTo, trialInfo } = useActiveUser()
const [userStats, setUserStats] = useState(null)
+ const [loading, setLoading] = useState(true)
+ const [downloading, setDownloading] = useState(false)
+ const progressRef = useRef(null)
useEffect(() => {
- const userId = user?.id
- if (!userId) return
+ if (userLoading) return
+ const currentUserId = user?.id || userId
+ if (!currentUserId) {
+ setLoading(false)
+ return
+ }
async function fetchStats() {
try {
const res = await fetch(`/api/users/${userId}/stats`)
@@ -33,6 +39,7 @@ export default function DashboardPage() {
const handleExport = async () => {
try {
+ setDownloading(true)
const score = isNew ? "0 / 0" : `${userStats?.today_score || 0} / ${userStats?.today_max_score || 60}`
const accuracy = isNew ? "0%" : `${userStats?.overall_accuracy || 0}%`
const qs = isNew ? "0" : (userStats?.total_questions_attempted || 0).toLocaleString()
@@ -57,6 +64,8 @@ export default function DashboardPage() {
window.URL.revokeObjectURL(blobUrl)
} catch (err) {
console.error("Failed to export image", err)
+ } finally {
+ setDownloading(false)
}
}
@@ -89,8 +98,9 @@ export default function DashboardPage() {
Your overall progress, scores, and active study plan at a glance.
-