Fix dashboard share card by replacing htmlToImage with dedicated OG API route
This commit is contained in:
@@ -5,7 +5,6 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/com
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { BrainCircuit, Play, ChevronRight, Activity, Target, CheckCircle2, AlertTriangle, TrendingUp, Calendar, Zap, LayoutDashboard, Share2, Trophy, Lock, ArrowRight, Clock } from "lucide-react"
|
||||
import * as htmlToImage from 'html-to-image'
|
||||
import { MistakeHeatmap } from "@/components/AI/MistakeHeatmap"
|
||||
import { AdaptiveStudyPlan } from "@/components/AI/AdaptiveStudyPlan"
|
||||
import { useActiveUser } from "@/hooks/useActiveUser"
|
||||
@@ -33,16 +32,31 @@ export default function DashboardPage() {
|
||||
}, [user?.id])
|
||||
|
||||
const handleExport = async () => {
|
||||
if (progressRef.current) {
|
||||
try {
|
||||
const dataUrl = await htmlToImage.toPng(progressRef.current, { backgroundColor: '#09090b' })
|
||||
const link = document.createElement('a')
|
||||
link.download = 'pragativeer-progress.png'
|
||||
link.href = dataUrl
|
||||
link.click()
|
||||
} catch (err) {
|
||||
console.error("Failed to export image", err)
|
||||
}
|
||||
try {
|
||||
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()
|
||||
const rank = isNew ? "#--" : `#${userStats?.city_rank || 1} / ${userStats?.city_total || 50}`
|
||||
|
||||
const target = user?.target_exam === "NEET" ? "NEET" : "JEE"
|
||||
const plan = user?.tier === "Al_Coach" ? "AI Coach" : user?.tier || "Free"
|
||||
const name = user?.name || "Student"
|
||||
|
||||
const url = `/api/og/dashboard?score=${encodeURIComponent(score)}&accuracy=${encodeURIComponent(accuracy)}&qs=${encodeURIComponent(qs)}&rank=${encodeURIComponent(rank)}&name=${encodeURIComponent(name)}&target=${target}&plan=${encodeURIComponent(plan)}`
|
||||
|
||||
const res = await fetch(url)
|
||||
const blob = await res.blob()
|
||||
const blobUrl = window.URL.createObjectURL(blob)
|
||||
|
||||
const link = document.createElement('a')
|
||||
link.download = 'pragativeer-dashboard.png'
|
||||
link.href = blobUrl
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
window.URL.revokeObjectURL(blobUrl)
|
||||
} catch (err) {
|
||||
console.error("Failed to export image", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user