diff --git a/frontend/src/api/AxiosInstance.ts b/frontend/src/api/AxiosInstance.ts index 56f81d2..27d276e 100644 --- a/frontend/src/api/AxiosInstance.ts +++ b/frontend/src/api/AxiosInstance.ts @@ -1,6 +1,6 @@ import axios from "axios"; import {NETWORK} from "@/constants/api"; -import {checkAndSetToken, handleTokenError} from "@/api/Interceptors"; +import {checkAndSetToken, delayFulfilled, handleTokenError, waitingFulfilled} from "@/api/Interceptors"; export const axiosInstance = axios.create({ baseURL: `${import.meta.env.VITE_API}/api`, @@ -10,4 +10,5 @@ export const axiosInstance = axios.create({ }) axiosInstance.interceptors.request.use(checkAndSetToken); -axiosInstance.interceptors.response.use(response => response, handleTokenError); +axiosInstance.interceptors.request.use(delayFulfilled); +axiosInstance.interceptors.response.use(waitingFulfilled, handleTokenError); diff --git a/frontend/src/api/Interceptors.ts b/frontend/src/api/Interceptors.ts index 14210bc..b4553d4 100644 --- a/frontend/src/api/Interceptors.ts +++ b/frontend/src/api/Interceptors.ts @@ -1,4 +1,4 @@ -import {AxiosError, InternalAxiosRequestConfig} from "axios"; +import {AxiosError, AxiosResponse, InternalAxiosRequestConfig} from "axios"; import {TOKEN} from "@/constants/api"; import {PATH} from "@/constants/path"; import {reIssueToken} from "@/api/auth/ReIssueToken"; @@ -54,3 +54,27 @@ export const handleTokenError = async(error: AxiosError) => { throw new HTTPError(status, data.message, data.code); } + + +export const delayFulfilled = (config: InternalAxiosRequestConfig )=> ({ + ...config, + p0: performance.now(), +}); + +export const waitingFulfilled = async (response: AxiosResponse) => { + const minimumDelay = 1000; + const latency = performance.now() - response.config.p0; + const shouldNotDelay = minimumDelay < latency; + + if (shouldNotDelay) { + return response; + } + + const remainder = minimumDelay - latency; + const [responseWithDelay] = await Promise.all([ + response, + new Promise((resolve) => setTimeout(resolve, remainder)), + ]); + return responseWithDelay; +} + diff --git a/frontend/src/api/index.d.ts b/frontend/src/api/index.d.ts index d70da11..f7c5cbb 100644 --- a/frontend/src/api/index.d.ts +++ b/frontend/src/api/index.d.ts @@ -4,4 +4,8 @@ declare module 'axios' { export interface AxiosRequestConfig { useAuth: boolean; } + + export interface InternalAxiosRequestConfig { + p0: number; + } } diff --git a/frontend/src/components/InterviewCreatorForm/InterviewCreateForm.tsx b/frontend/src/components/InterviewCreatorForm/InterviewCreateForm.tsx index 8f66ce5..96355da 100644 --- a/frontend/src/components/InterviewCreatorForm/InterviewCreateForm.tsx +++ b/frontend/src/components/InterviewCreatorForm/InterviewCreateForm.tsx @@ -2,7 +2,6 @@ import {Button, ModalBody, ModalContent, ModalHeader, Slider} from "@nextui-org/ import {problemCount, tailQuestionCount} from "@/components/InterviewCreatorForm/InterviewCreateForm.constant"; import {InterviewSettings} from "@/types/interview"; import {useInterviewCreateMutation} from "@/hooks/api/interview/useInterviewCreateMutation"; -import {useCallback} from "react"; import {useInterviewCreateForm} from "@/components/InterviewCreatorForm/useInterviewCreateForm"; @@ -46,13 +45,9 @@ interface InterviewCreateFormProps { } const InterviewCreateForm = ({ interviewSettings: {questionSetId, count, tailQuestionDepth}}: InterviewCreateFormProps) => { - const {mutate} = useInterviewCreateMutation(); + const {mutate, isPending,isSuccess} = useInterviewCreateMutation(); const {interviewCreateForm, handleOnChange} = useInterviewCreateForm({tailQuestionDepth, totalProblemCount:count}) - const handleInterviewCreate = useCallback(() => { - mutate({questionSetId, ...interviewCreateForm}); - }, [interviewCreateForm]); - return ( {() => ( @@ -78,7 +73,9 @@ const InterviewCreateForm = ({ interviewSettings: {questionSetId, count, tailQue

*아직 지원하지 않습니다.

- + )} diff --git a/frontend/src/components/InterviewForm/InterviewForm.tsx b/frontend/src/components/InterviewForm/InterviewForm.tsx index ccfec93..54ae8a3 100644 --- a/frontend/src/components/InterviewForm/InterviewForm.tsx +++ b/frontend/src/components/InterviewForm/InterviewForm.tsx @@ -21,6 +21,7 @@ const border = "1px solid rgb(54, 54, 54)"; const InterviewForm = ({interviewId}: InterviewFormProps) => { const { interview, + interviewLoading, handleSubmit, handlePass, chatList, @@ -51,25 +52,25 @@ const InterviewForm = ({interviewId}: InterviewFormProps) => { borderLeft: border }}>
- +
-
-