Skip to content

Commit 22e3040

Browse files
authored
Refactor: streamline code
1 parent 013f493 commit 22e3040

File tree

1 file changed

+1
-184
lines changed

1 file changed

+1
-184
lines changed

app/dashboard/interview/[interviewId]/start/_components/RecordAnswerSection.jsx

Lines changed: 1 addition & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,8 @@ const RecordAnswerSection = ({
111111
let MockJsonResp = result.response.text();
112112
console.log(MockJsonResp);
113113

114-
// Removing possible extra text around JSON
115114
MockJsonResp = MockJsonResp.replace("```json", "").replace("```", "");
116-
117-
// Attempt to parse JSON
115+
118116
let jsonFeedbackResp;
119117
try {
120118
jsonFeedbackResp = JSON.parse(MockJsonResp);
@@ -177,189 +175,8 @@ const RecordAnswerSection = ({
177175
)}
178176
</Button>
179177
</div>
180-
{/* Check transcription code */}
181-
{/* {userAnswer && (
182-
<div className="mt-4 p-4 bg-gray-100 rounded-lg">
183-
<h3 className="font-bold">Transcribed Answer:</h3>
184-
<p>{userAnswer}</p>
185-
</div>
186-
)} */}
187178
</div>
188179
);
189180
};
190181

191182
export default RecordAnswerSection;
192-
193-
194-
195-
196-
197-
198-
199-
200-
201-
202-
203-
204-
205-
206-
207-
208-
209-
210-
// "use client";
211-
// import { Button } from "@/components/ui/button";
212-
// import Image from "next/image";
213-
// import React, { useContext, useEffect, useState } from "react";
214-
// import Webcam from "react-webcam";
215-
// import useSpeechToText from "react-hook-speech-to-text";
216-
// import { Mic } from "lucide-react";
217-
// import { toast } from "sonner";
218-
// import { chatSession } from "@/utils/GeminiAIModal";
219-
// import { db } from "@/utils/db";
220-
// import { UserAnswer } from "@/utils/schema";
221-
// import { useUser } from "@clerk/nextjs";
222-
// import moment from "moment";
223-
// import { WebCamContext } from "@/app/dashboard/layout";
224-
225-
// const RecordAnswerSection = ({
226-
// mockInterviewQuestion,
227-
// activeQuestionIndex,
228-
// interviewData,
229-
// }) => {
230-
// const [userAnswer, setUserAnswer] = useState("");
231-
// const { user } = useUser();
232-
// const [loading, setLoading] = useState(false);
233-
// const {
234-
// error,
235-
// interimResult,
236-
// isRecording,
237-
// results,
238-
// startSpeechToText,
239-
// stopSpeechToText,
240-
// setResults,
241-
// } = useSpeechToText({
242-
// continuous: true,
243-
// useLegacyResults: false,
244-
// });
245-
// const { webCamEnabled, setWebCamEnabled } = useContext(WebCamContext);
246-
247-
// useEffect(() => {
248-
// results.map((result) =>
249-
// setUserAnswer((prevAns) => prevAns + result?.transcript)
250-
// );
251-
// }, [results]);
252-
253-
// useEffect(() => {
254-
// if (!isRecording && userAnswer.length > 10) {
255-
// updateUserAnswer();
256-
// }
257-
// // if (userAnswer?.length < 10) {
258-
// // setLoading(false);
259-
// // toast("Error while saving your answer, Please record again");
260-
// // return;
261-
// // }
262-
// }, [userAnswer]);
263-
264-
// const StartStopRecording = async () => {
265-
// if (isRecording) {
266-
// stopSpeechToText();
267-
// } else {
268-
// startSpeechToText();
269-
// }
270-
// };
271-
272-
// const updateUserAnswer = async () => {
273-
// try {
274-
// console.log(userAnswer);
275-
// setLoading(true);
276-
// const feedbackPrompt =
277-
// "Question:" +
278-
// mockInterviewQuestion[activeQuestionIndex]?.Question +
279-
// ", User Answer:" +
280-
// userAnswer +
281-
// " , Depends on question and user answer for given interview question" +
282-
// " please give us rating for answer and feedback as area of improvement if any " +
283-
// "in just 3 to 5 lines to improve it in JSON format with rating field and feedback field";
284-
285-
// const result = await chatSession.sendMessage(feedbackPrompt);
286-
287-
// let MockJsonResp = result.response.text();
288-
// console.log(MockJsonResp);
289-
290-
// // Removing possible extra text around JSON
291-
// MockJsonResp = MockJsonResp.replace("```json", "").replace("```", "");
292-
293-
// // Attempt to parse JSON
294-
// let jsonFeedbackResp;
295-
// try {
296-
// jsonFeedbackResp = JSON.parse(MockJsonResp);
297-
// } catch (e) {
298-
// throw new Error("Invalid JSON response: " + MockJsonResp);
299-
// }
300-
301-
// const resp = await db.insert(UserAnswer).values({
302-
// mockIdRef: interviewData?.mockId,
303-
// question: mockInterviewQuestion[activeQuestionIndex]?.Question,
304-
// correctAns: mockInterviewQuestion[activeQuestionIndex]?.Answer,
305-
// userAns: userAnswer,
306-
// feedback: jsonFeedbackResp?.feedback,
307-
// rating: jsonFeedbackResp?.rating,
308-
// userEmail: user?.primaryEmailAddress?.emailAddress,
309-
// createdAt: moment().format("YYYY-MM-DD"),
310-
// });
311-
312-
// if (resp) {
313-
// toast("User Answer recorded successfully");
314-
// }
315-
// setUserAnswer("");
316-
// setResults([]);
317-
// setLoading(false);
318-
// } catch (error) {
319-
// console.error(error);
320-
// toast("An error occurred while recording the user answer");
321-
// setLoading(false);
322-
// }
323-
// };
324-
325-
// return (
326-
// <div className="flex flex-col items-center justify-center overflow-hidden">
327-
// <div className="flex flex-col justify-center items-center rounded-lg p-5 bg-black mt-4 w-[30rem] ">
328-
// {webCamEnabled ? (
329-
// <Webcam
330-
// mirrored={true}
331-
// style={{ height: 250, width: "100%", zIndex: 10 }}
332-
// />
333-
// ) : (
334-
// <Image src={"/camera.jpg"} width={200} height={200} />
335-
// )}
336-
// </div>
337-
// <div className="md:flex mt-4 md:mt-8 md:gap-5">
338-
// <div className="my-4 md:my-0">
339-
// <Button
340-
// // className={`${webCamEnabled ? "w-full" : "w-full"}`}
341-
// onClick={() => setWebCamEnabled((prev) => !prev)}
342-
// >
343-
// {webCamEnabled ? "Close WebCam" : "Enable WebCam"}
344-
// </Button>
345-
// </div>
346-
// <Button
347-
// varient="outline"
348-
// // className="my-10"
349-
// onClick={StartStopRecording}
350-
// disabled={loading}
351-
// >
352-
// {isRecording ? (
353-
// <h2 className="text-red-400 flex gap-2 ">
354-
// <Mic /> Stop Recording...
355-
// </h2>
356-
// ) : (
357-
// " Record Answer"
358-
// )}
359-
// </Button>
360-
// </div>
361-
// </div>
362-
// );
363-
// };
364-
365-
// export default RecordAnswerSection;

0 commit comments

Comments
 (0)