Improved the Speaking Generation
This commit is contained in:
@@ -7,6 +7,7 @@ import {convertCamelCaseToReadable} from "@/utils/string";
|
|||||||
import {Tab} from "@headlessui/react";
|
import {Tab} from "@headlessui/react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
|
import moment from "moment";
|
||||||
import {useRouter} from "next/router";
|
import {useRouter} from "next/router";
|
||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
import {BsArrowRepeat, BsCheck} from "react-icons/bs";
|
import {BsArrowRepeat, BsCheck} from "react-icons/bs";
|
||||||
@@ -19,6 +20,7 @@ const PartTab = ({part, index, setPart}: {part?: SpeakingPart; index: number; se
|
|||||||
const generate = () => {
|
const generate = () => {
|
||||||
setPart(undefined);
|
setPart(undefined);
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.get(`/api/exam/speaking/generate/speaking_task_${index}`)
|
.get(`/api/exam/speaking/generate/speaking_task_${index}`)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
@@ -38,11 +40,15 @@ const PartTab = ({part, index, setPart}: {part?: SpeakingPart; index: number; se
|
|||||||
toast.info("This will take quite a while, please do not leave this page or close the tab/window.");
|
toast.info("This will take quite a while, please do not leave this page or close the tab/window.");
|
||||||
|
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
const initialTime = moment();
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.post(`/api/exam/speaking/generate/speaking/generate_${index === 3 ? "interactive" : "speaking"}_video`, part)
|
.post(`/api/exam/speaking/generate/speaking/generate_${index === 3 ? "interactive" : "speaking"}_video`, part)
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
playSound(typeof result.data === "string" ? "error" : "check");
|
const isError = typeof result.data === "string" || moment().diff(initialTime, "seconds") < 60;
|
||||||
if (typeof result.data === "string") return toast.error("Something went wrong, please try to generate the video again.");
|
|
||||||
|
playSound(isError ? "error" : "check");
|
||||||
|
if (isError) return toast.error("Something went wrong, please try to generate the video again.");
|
||||||
setPart({...part, result: result.data});
|
setPart({...part, result: result.data});
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
@@ -98,7 +104,7 @@ const PartTab = ({part, index, setPart}: {part?: SpeakingPart; index: number; se
|
|||||||
<span className={clsx("font-bold text-2xl text-ielts-speaking")}>Generating...</span>
|
<span className={clsx("font-bold text-2xl text-ielts-speaking")}>Generating...</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{part && (
|
{part && !isLoading && (
|
||||||
<div className="flex flex-col gap-2 w-full overflow-y-scroll scrollbar-hide h-96">
|
<div className="flex flex-col gap-2 w-full overflow-y-scroll scrollbar-hide h-96">
|
||||||
<h3 className="text-xl font-semibold">{part.topic}</h3>
|
<h3 className="text-xl font-semibold">{part.topic}</h3>
|
||||||
{part.question && <span className="w-full">{part.question}</span>}
|
{part.question && <span className="w-full">{part.question}</span>}
|
||||||
|
|||||||
Reference in New Issue
Block a user