-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtyping-results.tsx
More file actions
94 lines (89 loc) · 3.73 KB
/
typing-results.tsx
File metadata and controls
94 lines (89 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"use client";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogTrigger,
DialogFooter,
} from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { BarChart2 } from "lucide-react";
import { ChartContainer, ChartTooltip, ChartTooltipContent } from "@/components/ui/chart";
import { Bar, XAxis, YAxis, CartesianGrid, BarChart as RechartsBarChart } from "recharts";
type TypingResultsProps = {
wpm: number;
cpm: number;
accuracy: number;
errors: number;
time: number;
open: boolean;
onOpenChange: (open: boolean) => void;
};
export default function TypingResults({ wpm, cpm, accuracy, errors, time, open, onOpenChange }: TypingResultsProps) {
const chartData = [
{ name: "WPM", value: Math.round(wpm), fill: "hsl(var(--primary))" },
{ name: "CPM", value: Math.round(cpm), fill: "hsl(var(--primary))" },
{ name: "Accuracy", value: Math.round(accuracy), fill: "hsl(var(--accent))" },
{ name: "Errors", value: errors, fill: "hsl(var(--destructive))" },
];
const chartConfig = {
value: {
label: "Value",
},
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogTrigger asChild>
<Button>
<BarChart2 className="mr-2" />
Detailed Analysis
</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle className="font-headline text-2xl">Typing Results</DialogTitle>
</DialogHeader>
<div className="grid gap-4 py-4">
<div className="flex justify-between items-center p-3 bg-muted rounded-lg">
<span className="text-muted-foreground">Words Per Minute (WPM)</span>
<span className="text-xl font-bold font-headline text-primary">{Math.round(wpm)}</span>
</div>
<div className="flex justify-between items-center p-3 bg-muted rounded-lg">
<span className="text-muted-foreground">Chars Per Minute (CPM)</span>
<span className="text-xl font-bold font-headline text-primary">{Math.round(cpm)}</span>
</div>
<div className="flex justify-between items-center p-3 bg-muted rounded-lg">
<span className="text-muted-foreground">Accuracy</span>
<span className="text-xl font-bold font-headline">{accuracy.toFixed(1)}%</span>
</div>
<div className="flex justify-between items-center p-3 bg-muted rounded-lg">
<span className="text-muted-foreground">Errors</span>
<span className="text-xl font-bold font-headline text-destructive">{errors}</span>
</div>
<div className="flex justify-between items-center p-3 bg-muted rounded-lg">
<span className="text-muted-foreground">Time Taken</span>
<span className="text-xl font-bold font-headline">{time.toFixed(1)}s</span>
</div>
<div className="mt-4">
<ChartContainer config={chartConfig} className="w-full h-[200px]">
<RechartsBarChart data={chartData} layout="vertical" margin={{ left: 10 }}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis type="number" hide />
<YAxis dataKey="name" type="category" tickLine={false} axisLine={false} />
<ChartTooltip
cursor={false}
content={<ChartTooltipContent hideLabel />}
/>
<Bar dataKey="value" radius={5} />
</RechartsBarChart>
</ChartContainer>
</div>
</div>
<DialogFooter>
<p className="text-sm text-muted-foreground">Great job! Keep practicing to improve your speed and accuracy.</p>
</DialogFooter>
</DialogContent>
</Dialog>
);
}