@@ -16,9 +16,12 @@ import { logoutUser } from "@/redux-store/slices/authSlice";
16
16
import { calculateAverage } from "@/lib/helpers/calculateUserAverage" ;
17
17
import ChartView from "@/components/ChartView" ;
18
18
import { ModeToggle } from "@/components/ui/toggle-theme" ;
19
+ import { useSubscription } from "@/hooks/useSubscription" ;
20
+ import History from "@/components/History" ;
19
21
20
22
export default function Component ( ) {
21
23
const dispatch = useAppDispatch ( ) ;
24
+ const { isProUser } = useSubscription ( ) ;
22
25
const { user } = useAuthStatus ( ) ;
23
26
const { results } = useResultStatus ( ) ;
24
27
const [ averagedata , setAverageData ] = useState ( {
@@ -29,18 +32,20 @@ export default function Component() {
29
32
if ( user ?. id ) {
30
33
dispatch ( getResultsInfo ( String ( user ?. id ) ) ) ;
31
34
}
35
+ } , [ dispatch , user ?. id ] ) ;
36
+ useEffect ( ( ) => {
32
37
if ( results ) {
33
38
const res = calculateAverage ( results ) ;
34
39
setAverageData ( res ) ;
35
40
}
36
- } , [ results , user ?. id , dispatch ] ) ;
41
+ } , [ results ] ) ;
37
42
return (
38
43
< div className = "flex h-screen w-full flex-col p-0" >
39
44
< div className = "flex h-full flex-row" >
40
45
< div className = "flex flex-col flex-1" >
41
46
< header className = "h-16 px-4 border-b shrink-0 md:px-6 flex items-center" >
42
47
< div className = "flex items-center justify-end w-full gap-4 md:ml-auto md:gap-2 lg:gap-4" >
43
- { ! user ?. isProUser && (
48
+ { ! isProUser && (
44
49
< Link
45
50
className = "text-gray-600 hover:text-gray-900 dark:text-gray-200"
46
51
to = "/pricing"
@@ -86,12 +91,12 @@ export default function Component() {
86
91
< Card >
87
92
< CardHeader className = "flex flex-row items-center justify-between pb-2 space-y-0" >
88
93
< CardTitle className = "text-sm font-medium" >
89
- Average score
94
+ Average wpm
90
95
</ CardTitle >
91
96
</ CardHeader >
92
97
< CardContent >
93
98
< div className = "text-2xl font-bold text-green-500" >
94
- { averagedata . averageScore }
99
+ { averagedata . averageScore . toFixed ( 1 ) }
95
100
</ div >
96
101
</ CardContent >
97
102
</ Card >
@@ -108,39 +113,53 @@ export default function Component() {
108
113
</ CardContent >
109
114
</ Card >
110
115
</ div >
111
- < div className = "grid gap-4 md:grid-cols-2" >
112
- < Card >
113
- < CardHeader className = "pb-4" >
114
- < CardTitle className = "text-lg font-medium" >
115
- Score Overview
116
- </ CardTitle >
117
- < CardDescription >
118
- Your score's Variations in the typing test
119
- </ CardDescription >
120
- </ CardHeader >
121
- < CardContent className = "" >
122
- { /* Chart Component Here */ }
123
- < ChartView type = "Score" />
124
- </ CardContent >
125
- </ Card >
126
- < Card >
127
- < CardHeader className = "pb-4" >
128
- < CardTitle className = "text-lg font-medium" >
129
- Accuracy Overview
130
- </ CardTitle >
131
- < CardDescription >
132
- Your accuracy Variations in the typing test
133
- </ CardDescription >
134
- </ CardHeader >
135
- < CardContent className = "" >
136
- { /* Chart Component Here */ }
137
- < ChartView type = "Accuracy" />
138
- </ CardContent >
139
- </ Card >
116
+ < div >
117
+ < h1 className = "text-xl font-bold text-black dark:text-white mb-4" >
118
+ Test History
119
+ </ h1 >
120
+ < History results = { results } />
140
121
</ div >
122
+ { isProUser && (
123
+ < div className = "grid gap-4 md:grid-cols-2" >
124
+ < Card >
125
+ < CardHeader className = "pb-4" >
126
+ < CardTitle className = "text-lg font-medium" >
127
+ Wpm Overview
128
+ </ CardTitle >
129
+ < CardDescription >
130
+ Your wpm Variations in the typing test
131
+ </ CardDescription >
132
+ </ CardHeader >
133
+ < CardContent className = "" >
134
+ { /* Chart Component Here */ }
135
+ < ChartView type = "Wpm" />
136
+ </ CardContent >
137
+ </ Card >
138
+ < Card >
139
+ < CardHeader className = "pb-4" >
140
+ < CardTitle className = "text-lg font-medium" >
141
+ Accuracy Overview
142
+ </ CardTitle >
143
+ < CardDescription >
144
+ Your accuracy Variations in the typing test
145
+ </ CardDescription >
146
+ </ CardHeader >
147
+ < CardContent className = "" >
148
+ { /* Chart Component Here */ }
149
+ < ChartView type = "Accuracy" />
150
+ </ CardContent >
151
+ </ Card >
152
+ </ div >
153
+ ) }
141
154
</ main >
142
155
</ div >
143
156
</ div >
157
+ < Button
158
+ className = "fixed bottom-7 left-10 object-cover w-fit shadow-2xl bg-gradient-to-r from-purple-400 to-fuchsia-600"
159
+ variant = { "destructive" }
160
+ >
161
+ { isProUser ? "Manage Subscriptions" : "Go Pro" }
162
+ </ Button >
144
163
</ div >
145
164
) ;
146
165
}
0 commit comments