Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/app/components/Player/PlayerForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export const PlayerForm = ({ player }: Props) => {
motto: player ? player.motto : "",
emoji: player ? player.emoji : "",
});

const [emojiSelectorOpen, setEmojiSelectorOpen] = useState<boolean>(false);
const [isButtonPressed, setButtonPressed] = useState(false);

const router = useRouter();

Expand All @@ -51,6 +53,7 @@ export const PlayerForm = ({ player }: Props) => {
};

const submitNewPlayer = async (newPlayer: NewPlayer) => {
setButtonPressed(!isButtonPressed);

Copilot AI Oct 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This toggle logic is incorrect. The button should be disabled during submission and re-enabled after completion. This should be setButtonPressed(true) at the start of submission and setButtonPressed(false) after the request completes (both success and error cases).

Copilot uses AI. Check for mistakes.
const res = await fetch("/api/player/", {
method: "POST",
headers: {
Expand Down Expand Up @@ -129,7 +132,7 @@ export const PlayerForm = ({ player }: Props) => {
</div>
<TextButton
buttonType="button"
disabled={!isValid}
disabled={!isValid || isButtonPressed}
onClick={submit}
RightIcon={HiUserAdd}
text={isUpdate ? "Save changes" : "Create player"}
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/ui/PlayerSearch/PlayerSearchLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const PlayerSearchLink = ({ visible, onClick, onBlur }: Props) => {
return (
<div className="flex w-full flex-col gap-2">
<input
className="w-full rounded-lg bg-white p-3"
className="w-full rounded-lg bg-white p-3 text-black"
placeholder={"Search for a player"}
onClick={onClick}
onKeyDown={handleKeyPress}
Expand Down
48 changes: 33 additions & 15 deletions src/server/db/players/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,41 @@ const searchPlayers = async (
query: string,
limit?: number,
): Promise<PlayerModel[]> => {
const colOptions = ["first_name", "last_name", "nickname", "id"];
const permutations = permutator(colOptions);

const options = permutations.map((perm) => {
return Sequelize.where(
Sequelize.fn("concat", ...perm.map((col) => Sequelize.col(col))),
{
[Op.iLike]: `%${query.replaceAll(" ", "%")}%`,
},
try {
const colOptions = ["first_name", "last_name", "nickname", "id"];
const permutations = permutator(colOptions);

const queryParts = query.split(" ").filter((part) => part.length > 0);

const options = await Promise.all(
queryParts.map(async (part) => {
return await Promise.all(
permutations.map(async (perm) => {
Comment on lines +137 to +140

Copilot AI Oct 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nested Promise.all creates unnecessary async operations. The inner permutations.map doesn't perform any async operations, so the inner Promise.all and async/await are redundant and could impact performance.

Copilot uses AI. Check for mistakes.
return Sequelize.where(
Sequelize.fn("concat", ...perm.map((col) => Sequelize.col(col))),
{
[Op.iLike]: `${part}%`,
},
);
}),
);
}),
);
});

const players = await PlayerModel.findAll({
where: { [Op.or]: options },
limit: limit,
});
return players;
const whereClause = {
[Op.and]: options.map((opts) => ({ [Op.or]: opts })),
};

const players = await PlayerModel.findAll({
where: whereClause,
limit: limit,
});

return players;
} catch (error) {
console.error("Error in searchPlayers:", error);
throw error;
}
};

export {
Expand Down