.
This commit is contained in:
1 parent
2379051196
commit
4baea89f89
6 files changed
+9834
-48
No files matched your search
@@ -20,7 +20,12 @@ import {
|
||||
profileIconUrl,
|
||||
} from '../lib/ddragon';
|
||||
import { positionIcon, positionLabel } from '../lib/league';
|
||||
import type { ApiRiotLaneStats, Position, TeamSide } from '../api/types';
|
||||
import type {
|
||||
ApiAuction,
|
||||
ApiRiotLaneStats,
|
||||
Position,
|
||||
TeamSide,
|
||||
} from '../api/types';
|
||||
|
||||
type CaptainRole = {
|
||||
side: TeamSide;
|
||||
@@ -46,6 +51,22 @@ function isCurrentBidder(
|
||||
);
|
||||
}
|
||||
|
||||
function getAuctionUpdatedAt(auction: ApiAuction | null | undefined) {
|
||||
if (!auction) return 0;
|
||||
return Date.parse(auction.updatedAt ?? auction.createdAt ?? '') || 0;
|
||||
}
|
||||
|
||||
function pickLatestAuction(
|
||||
socketAuction: ApiAuction | null,
|
||||
queryAuction: ApiAuction | undefined,
|
||||
) {
|
||||
if (!socketAuction) return queryAuction ?? null;
|
||||
if (!queryAuction) return socketAuction;
|
||||
return getAuctionUpdatedAt(queryAuction) > getAuctionUpdatedAt(socketAuction)
|
||||
? queryAuction
|
||||
: socketAuction;
|
||||
}
|
||||
|
||||
const AUCTION_MAX_TEAM_SIZE = 5;
|
||||
const LANE_ROWS: Position[] = ['TOP', 'JGL', 'MID', 'ADC', 'SUP'];
|
||||
const POSITION_TO_RIOT_LANE = {
|
||||
@@ -554,7 +575,9 @@ export default function AuctionPage() {
|
||||
(membership) => membership.community?._id === DEFAULT_COMMUNITY_ID,
|
||||
)?.user ?? null;
|
||||
const matchQuery = useMatch(id, DEFAULT_COMMUNITY_ID);
|
||||
const auctionQuery = useAuction(id, DEFAULT_COMMUNITY_ID);
|
||||
const auctionQuery = useAuction(id, DEFAULT_COMMUNITY_ID, {
|
||||
refetchInterval: 5000,
|
||||
});
|
||||
const socket = useAuctionSocket(id);
|
||||
const captainSide = useDevCaptainSide();
|
||||
const [captainGroupIndex, setCaptainGroupIndex] = useState(1);
|
||||
@@ -566,7 +589,7 @@ export default function AuctionPage() {
|
||||
return () => window.clearInterval(timer);
|
||||
}, []);
|
||||
|
||||
const liveAuction = socket.auction ?? auctionQuery.data ?? null;
|
||||
const liveAuction = pickLatestAuction(socket.auction, auctionQuery.data);
|
||||
const auctionState =
|
||||
liveAuction && matchQuery.data
|
||||
? mapApiAuctionToAuctionState(liveAuction, matchQuery.data, new Date(now))
|
||||
|
||||
Reference in new issue
Block a user