-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult.tsx
39 lines (37 loc) · 1.02 KB
/
result.tsx
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
import { useEffect, useState } from "react";
import { NextPage } from "next";
import { trpc } from "src/utils/trpc";
import { Gauge } from "@components/result";
const Result: NextPage<Record<string, unknown>> = () => {
const [sessionId, setSessionId] = useState<string>("");
const [isQueryEnabled, setIsQueryEnabled] = useState(false);
const { data, isLoading, isError } = trpc.useQuery(
["resultBySessionId", sessionId],
{
enabled: isQueryEnabled,
}
);
useEffect(() => {
const session = sessionStorage.getItem("sessionId");
if (session) {
setSessionId(session);
setIsQueryEnabled(true);
}
}, []);
return (
<div style={{ textAlign: "center" }}>
{data ? (
<Gauge
label="Introver/extrover result:"
units="Being 0 most introvert to 100 most extrovert"
value={data?.score}
/>
) : isError ? (
<p>Error fetching data</p>
) : (
isLoading && <p>Loding...</p>
)}
</div>
);
};
export default Result;