Skip to content

Commit

Permalink
fix: 카드 옵션 선택 시 409 요청 오류 throttle로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
sooyeoniya committed Aug 23, 2024
1 parent 28d7d39 commit 4c23011
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { useCookies } from "react-cookie";
import { RushAPI } from "@/apis/rushAPI.ts";
import { CARD_OPTION } from "@/constants/Rush/rushCard.ts";
Expand All @@ -16,18 +16,29 @@ export default function RushCardComparison() {
const gameState = useRushGameStateContext();
const dispatch = useRushGameDispatchContext();
const { getRushUserParticipationStatus } = useFetchRushUserParticipationStatus();
const [throttle, setThrottle] = useState<boolean>(false);

const {
data: postSelectedRushOptionResponse,
isSuccess: isSuccessPostSelectedRushOption,
isLoading: isLoadingPostSelectedRushOption,
fetchData: postSelectedRushOptionApply,
} = useFetch<RushEventStatusCodeResponse, { token: string; optionId: CardOption }>(
({ token, optionId }) => RushAPI.postSelectedRushOptionApply(token, optionId)
);

const handleCardSelection = async (optionId: CardOption) => {
await postSelectedRushOptionApply({ token: cookies[COOKIE_KEY.ACCESS_TOKEN], optionId });
dispatch({ type: RUSH_ACTION.SET_USER_OPTION, payload: optionId });
if (!throttle && !isLoadingPostSelectedRushOption) {
await postSelectedRushOptionApply({
token: cookies[COOKIE_KEY.ACCESS_TOKEN],
optionId,
});
dispatch({ type: RUSH_ACTION.SET_USER_OPTION, payload: optionId });
setThrottle(true);
setTimeout(() => {
setThrottle(false);
}, 1000);
}
};

useEffect(() => {
Expand Down

0 comments on commit 4c23011

Please sign in to comment.