fix : loading game from CC and lichess
This commit is contained in:
@@ -23,7 +23,7 @@ export default function ChessComInput({ onSelect }: Props) {
|
||||
"chesscom-username",
|
||||
""
|
||||
);
|
||||
const debouncedUsername = useDebounce(chessComUsername, 200);
|
||||
const debouncedUsername = useDebounce(chessComUsername, 300);
|
||||
const setBoardOrientation = useSetAtom(boardOrientationAtom);
|
||||
|
||||
const {
|
||||
@@ -33,7 +33,9 @@ export default function ChessComInput({ onSelect }: Props) {
|
||||
} = useQuery({
|
||||
queryKey: ["CCUserGames", debouncedUsername],
|
||||
enabled: !!debouncedUsername,
|
||||
queryFn: () => getChessComUserRecentGames(debouncedUsername ?? ""),
|
||||
queryFn: ({ signal }) =>
|
||||
getChessComUserRecentGames(debouncedUsername ?? "", signal),
|
||||
retry: 1,
|
||||
});
|
||||
|
||||
return (
|
||||
@@ -72,7 +74,7 @@ export default function ChessComInput({ onSelect }: Props) {
|
||||
onClick={() => {
|
||||
setBoardOrientation(
|
||||
chessComUsername.toLowerCase() !==
|
||||
game.black.username.toLowerCase()
|
||||
game.black?.username?.toLowerCase()
|
||||
);
|
||||
onSelect(game.pgn);
|
||||
}}
|
||||
@@ -80,16 +82,20 @@ export default function ChessComInput({ onSelect }: Props) {
|
||||
key={game.uuid}
|
||||
>
|
||||
<ListItemText
|
||||
primary={`${capitalize(game.white.username) || "White"} (${
|
||||
game.white.rating || "?"
|
||||
}) vs ${capitalize(game.black.username) || "Black"} (${
|
||||
game.black.rating || "?"
|
||||
primary={`${capitalize(game.white?.username || "white")} (${
|
||||
game.white?.rating || "?"
|
||||
}) vs ${capitalize(game.black?.username || "black")} (${
|
||||
game.black?.rating || "?"
|
||||
})`}
|
||||
secondary={`${capitalize(game.time_class)} played at ${new Date(
|
||||
game.end_time * 1000
|
||||
)
|
||||
.toLocaleString()
|
||||
.slice(0, -3)}`}
|
||||
secondary={
|
||||
game.end_time
|
||||
? `${capitalize(game.time_class || "game")} played at ${new Date(
|
||||
game.end_time * 1000
|
||||
)
|
||||
.toLocaleString()
|
||||
.slice(0, -3)}`
|
||||
: undefined
|
||||
}
|
||||
slotProps={{
|
||||
primary: { noWrap: true },
|
||||
secondary: { noWrap: true },
|
||||
|
||||
@@ -23,7 +23,7 @@ export default function LichessInput({ onSelect }: Props) {
|
||||
"lichess-username",
|
||||
""
|
||||
);
|
||||
const debouncedUsername = useDebounce(lichessUsername, 200);
|
||||
const debouncedUsername = useDebounce(lichessUsername, 500);
|
||||
const setBoardOrientation = useSetAtom(boardOrientationAtom);
|
||||
|
||||
const {
|
||||
@@ -33,7 +33,9 @@ export default function LichessInput({ onSelect }: Props) {
|
||||
} = useQuery({
|
||||
queryKey: ["LichessUserGames", debouncedUsername],
|
||||
enabled: !!debouncedUsername,
|
||||
queryFn: () => getLichessUserRecentGames(debouncedUsername ?? ""),
|
||||
queryFn: ({ signal }) =>
|
||||
getLichessUserRecentGames(debouncedUsername ?? "", signal),
|
||||
retry: 1,
|
||||
});
|
||||
|
||||
return (
|
||||
@@ -72,7 +74,7 @@ export default function LichessInput({ onSelect }: Props) {
|
||||
onClick={() => {
|
||||
setBoardOrientation(
|
||||
lichessUsername.toLowerCase() !==
|
||||
game.players?.black?.user?.name.toLowerCase()
|
||||
game.players?.black?.user?.name?.toLowerCase()
|
||||
);
|
||||
onSelect(game.pgn);
|
||||
}}
|
||||
@@ -87,11 +89,15 @@ export default function LichessInput({ onSelect }: Props) {
|
||||
capitalize(game.players?.black?.user?.name || "black") ||
|
||||
"Black"
|
||||
} (${game.players?.black?.rating || "?"})`}
|
||||
secondary={`${capitalize(game.speed)} played at ${new Date(
|
||||
secondary={
|
||||
game.lastMoveAt
|
||||
)
|
||||
.toLocaleString()
|
||||
.slice(0, -3)}`}
|
||||
? `${capitalize(game.speed || "game")} played at ${new Date(
|
||||
game.lastMoveAt
|
||||
)
|
||||
.toLocaleString()
|
||||
.slice(0, -3)}`
|
||||
: undefined
|
||||
}
|
||||
slotProps={{
|
||||
primary: { noWrap: true },
|
||||
secondary: { noWrap: true },
|
||||
|
||||
Reference in New Issue
Block a user