fix(web): satisfy React hook lint rules
This commit is contained in:
1 parent
bb68be14fa
commit
a4215f86fb
8 files changed
+374
-256
No files matched your search
@@ -2,6 +2,7 @@ import {
|
||||
lazy,
|
||||
memo,
|
||||
Suspense,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useLayoutEffect,
|
||||
useMemo,
|
||||
@@ -51,7 +52,8 @@ import {
|
||||
teamIndexLabel,
|
||||
} from "../lib/league";
|
||||
import { internalMatchGamePath } from "../lib/internal-match-routes";
|
||||
import { formatRankDetail, RankBadge } from "../components/RankBadge";
|
||||
import { RankBadge } from "../components/RankBadge";
|
||||
import { formatRankDetail } from "../components/rankBadgeUtils";
|
||||
import type {
|
||||
ApiAuction,
|
||||
ApiAuctionChatMessage,
|
||||
@@ -1616,7 +1618,6 @@ function BidControls({
|
||||
serverTimeOffsetMs: number;
|
||||
onBid: (teamIndex: number, amount: number) => void;
|
||||
}) {
|
||||
const [bidAmount, setBidAmount] = useState(100);
|
||||
const minBid = state.currentBid + AUCTION_MIN_BID_POINTS;
|
||||
const activeTeam = captainRole
|
||||
? state.teams.find((team) => team.teamIndex === captainRole.teamIndex)
|
||||
@@ -1627,6 +1628,23 @@ function BidControls({
|
||||
? getReservedPointsAfterCurrentBid(activeTeam)
|
||||
: 0;
|
||||
const maxBid = activeTeam ? getMaxBidForTeam(activeTeam) : 0;
|
||||
const defaultBidAmount = Math.max(minBid, Math.ceil(minBid / 10) * 10);
|
||||
const bidContextKey = `${activeTeam?.teamIndex ?? "spectator"}:${maxBid}:${minBid}`;
|
||||
const [bidDraft, setBidDraft] = useState({
|
||||
contextKey: bidContextKey,
|
||||
amount: activeTeam
|
||||
? Math.min(maxBid, defaultBidAmount)
|
||||
: defaultBidAmount,
|
||||
});
|
||||
const bidAmount =
|
||||
bidDraft.contextKey === bidContextKey
|
||||
? bidDraft.amount
|
||||
: activeTeam
|
||||
? Math.min(maxBid, defaultBidAmount)
|
||||
: defaultBidAmount;
|
||||
const setBidAmount = (amount: number) => {
|
||||
setBidDraft({ contextKey: bidContextKey, amount });
|
||||
};
|
||||
const canAffordNextBid = !isActiveTeamFull && maxBid >= minBid;
|
||||
const isBidExpired = useIsDeadlineExpired(
|
||||
state.deadline,
|
||||
@@ -1637,11 +1655,6 @@ function BidControls({
|
||||
? Math.min(maxBid, Math.max(minBid, bidAmount))
|
||||
: Math.max(minBid, bidAmount);
|
||||
|
||||
useEffect(() => {
|
||||
const nextBid = Math.max(minBid, Math.ceil(minBid / 10) * 10);
|
||||
setBidAmount(activeTeam ? Math.min(maxBid, nextBid) : nextBid);
|
||||
}, [activeTeam, maxBid, minBid]);
|
||||
|
||||
if (state.phase !== "bidding") return null;
|
||||
|
||||
if (!activeTeam) {
|
||||
@@ -1843,7 +1856,10 @@ export default function AuctionPage() {
|
||||
const resetAuctionMutation = useResetAuction(DEFAULT_COMMUNITY_ID);
|
||||
const socket = useAuctionSocket(id);
|
||||
const captainTeamIndex = useDevCaptainTeamIndex();
|
||||
const [assignedPosition, setAssignedPosition] = useState<Position>("MID");
|
||||
const [assignedPositionDraft, setAssignedPositionDraft] = useState<{
|
||||
playerId: string | null;
|
||||
position: Position;
|
||||
}>({ playerId: null, position: "MID" });
|
||||
const [showCancelModal, setShowCancelModal] = useState(false);
|
||||
const [cancelConfirmText, setCancelConfirmText] = useState("");
|
||||
const [undoTargetSequence, setUndoTargetSequence] = useState<number | null>(
|
||||
@@ -1853,7 +1869,7 @@ export default function AuctionPage() {
|
||||
const historyBackTo = `${location.pathname}${location.search}${location.hash}`;
|
||||
const canConfirmAuctionCancel = cancelConfirmText.trim() === "예";
|
||||
|
||||
async function clearAuctionDataAfterCancel() {
|
||||
const clearAuctionDataAfterCancel = useCallback(async () => {
|
||||
if (!id) return;
|
||||
const auctionQueryKey = ["auction", DEFAULT_COMMUNITY_ID, id] as const;
|
||||
const auctionHistoryQueryKey = [
|
||||
@@ -1878,7 +1894,7 @@ export default function AuctionPage() {
|
||||
queryKey: ["match", DEFAULT_COMMUNITY_ID, id],
|
||||
exact: true,
|
||||
});
|
||||
}
|
||||
}, [id, queryClient]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!showCancelModal) return;
|
||||
@@ -1893,6 +1909,14 @@ export default function AuctionPage() {
|
||||
: null,
|
||||
[liveAuction, matchQuery.data],
|
||||
);
|
||||
const currentPlayerId = auctionState?.currentPlayer?.id ?? null;
|
||||
const assignedPosition =
|
||||
assignedPositionDraft.playerId === currentPlayerId
|
||||
? assignedPositionDraft.position
|
||||
: (auctionState?.currentPlayer?.mainPosition ?? "MID");
|
||||
const setAssignedPosition = (position: Position) => {
|
||||
setAssignedPositionDraft({ playerId: currentPlayerId, position });
|
||||
};
|
||||
const availableTeamIndexes = useMemo(() => {
|
||||
const indexes = new Set(
|
||||
(auctionState?.teams ?? []).map((team) => team.teamIndex),
|
||||
@@ -1907,12 +1931,6 @@ export default function AuctionPage() {
|
||||
};
|
||||
const chatSenderLabel = resolveChatSenderLabel(currentUser, captainRole);
|
||||
|
||||
useEffect(() => {
|
||||
if (auctionState?.currentPlayer) {
|
||||
setAssignedPosition(auctionState.currentPlayer.mainPosition);
|
||||
}
|
||||
}, [auctionState?.currentPlayer?.id]);
|
||||
|
||||
useEffect(() => {
|
||||
if (availableTeamIndexes.length === 0) return;
|
||||
if (
|
||||
@@ -1928,7 +1946,7 @@ export default function AuctionPage() {
|
||||
void clearAuctionDataAfterCancel().finally(() => {
|
||||
navigate(`/match/${id}`, { replace: true });
|
||||
});
|
||||
}, [id, navigate, socket.resetAt]);
|
||||
}, [clearAuctionDataAfterCancel, id, navigate, socket.resetAt]);
|
||||
|
||||
if (!DEFAULT_COMMUNITY_ID) {
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user