-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResult.tsx
More file actions
143 lines (134 loc) · 6.53 KB
/
Copy pathResult.tsx
File metadata and controls
143 lines (134 loc) · 6.53 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { BACKEND_URL } from "@/lib/config";
import axios from "axios";
import { useEffect, useState } from "react";
import { useNavigate, useParams } from "react-router";
import { Bot, Loader2, Sparkles, User } from "lucide-react";
import { Button } from "./ui/button";
import { cn } from "@/lib/utils";
interface ResultData {
transcript: { type: "Assistant" | "User"; content: string; createdAt: string }[];
score: number;
feedback: string;
status: "Done" | "InProgress" | "Pre";
}
export function Result() {
const { interviewId } = useParams();
const navigate = useNavigate();
const [result, setResult] = useState<ResultData>({
score: 0,
feedback: "",
transcript: [],
status: "Pre",
});
useEffect(() => {
const fetchResult = () =>
axios.get(`${BACKEND_URL}/api/v1/result/${interviewId}`).then((response) => {
setResult(response.data);
return response.data.status as ResultData["status"];
});
fetchResult();
const intervalId = setInterval(async () => {
const s = await fetchResult();
if (s === "Done") clearInterval(intervalId);
}, 5000);
return () => clearInterval(intervalId);
}, [interviewId]);
const ready = result.status === "Done";
return (
<main className="mx-auto min-h-screen w-full max-w-3xl px-6 py-12">
<header className="mb-10 flex items-center justify-between">
<div>
<h1 className="text-2xl font-semibold tracking-tight">Interview results</h1>
<p className="mt-1 text-sm text-muted-foreground">
Your feedback and full conversation transcript.
</p>
</div>
<Button variant="outline" onClick={() => navigate("/")}>
New interview
</Button>
</header>
{!ready ? (
<div className="flex flex-col items-center justify-center gap-4 rounded-xl border border-border bg-card/50 py-24 text-center">
<Loader2 className="size-7 animate-spin text-muted-foreground" />
<div>
<p className="font-medium">Analyzing your interview…</p>
<p className="mt-1 text-sm text-muted-foreground">
This usually takes a few seconds.
</p>
</div>
</div>
) : (
<div className="flex flex-col gap-8">
{/* Score + feedback */}
<section className="rounded-xl border border-border bg-card/60 p-6 backdrop-blur">
<div className="flex items-start justify-between gap-6">
<div className="flex items-center gap-2 text-sm font-medium text-muted-foreground">
<Sparkles className="size-4 text-violet-400" />
AI Feedback
</div>
<div className="flex shrink-0 items-baseline gap-1">
<span className="text-3xl font-bold tracking-tight">
{result.score}
</span>
<span className="text-sm text-muted-foreground">/ 10</span>
</div>
</div>
<p className="mt-4 whitespace-pre-wrap text-sm leading-relaxed text-foreground/90">
{result.feedback}
</p>
</section>
{/* Transcript */}
<section>
<h2 className="mb-4 text-sm font-medium text-muted-foreground">
Conversation
</h2>
<div className="flex flex-col gap-4">
{result.transcript.length === 0 && (
<p className="text-sm text-muted-foreground">
No messages were recorded for this interview.
</p>
)}
{result.transcript.map((m, i) => {
const isAi = m.type === "Assistant";
return (
<div
key={i}
className={cn(
"flex gap-3",
isAi ? "justify-start" : "flex-row-reverse",
)}
>
<div
className={cn(
"grid size-8 shrink-0 place-items-center rounded-full text-white",
isAi
? "bg-gradient-to-br from-violet-400 to-indigo-600"
: "bg-gradient-to-br from-emerald-300 to-teal-600",
)}
>
{isAi ? (
<Bot className="size-4" />
) : (
<User className="size-4" />
)}
</div>
<div
className={cn(
"max-w-[80%] rounded-2xl px-4 py-2.5 text-sm leading-relaxed",
isAi
? "rounded-tl-sm bg-card text-foreground"
: "rounded-tr-sm bg-primary text-primary-foreground",
)}
>
{m.content}
</div>
</div>
);
})}
</div>
</section>
</div>
)}
</main>
);
}