mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-01 15:48:23 -05:00
Fix seed page wrong order in some case Closes #799
This commit is contained in:
@@ -26,6 +26,7 @@ import { parseRequestFormData, requireUser, Unpacked, validate } from "~/utils";
|
||||
import { useUser } from "~/hooks/common";
|
||||
import { tournamentFrontPage } from "~/utils/urls";
|
||||
import { Navigate } from "~/components/Navigate";
|
||||
import clone from "just-clone";
|
||||
|
||||
const manageActionSchema = z.object({
|
||||
_action: z.enum(["CHECK_OUT", "CHECK_IN", "UNREGISTER"]),
|
||||
@@ -82,7 +83,7 @@ export default function ManageTab() {
|
||||
const user = useUser();
|
||||
const [, parentRoute] = useMatches();
|
||||
const tournament = parentRoute.data as FindTournamentByNameForUrlI;
|
||||
const teamsSorted = tournament.teams.sort((a, b) =>
|
||||
const teamsSorted = clone(tournament.teams).sort((a, b) =>
|
||||
a.name.localeCompare(b.name)
|
||||
);
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
useTransition,
|
||||
} from "@remix-run/react";
|
||||
import clsx from "clsx";
|
||||
import clone from "just-clone";
|
||||
import * as React from "react";
|
||||
import invariant from "tiny-invariant";
|
||||
import { z } from "zod";
|
||||
@@ -35,7 +36,7 @@ import { Button } from "~/components/Button";
|
||||
import { Catcher } from "~/components/Catcher";
|
||||
import { Draggable } from "~/components/Draggable";
|
||||
import { averageTeamMMRs } from "~/core/mmr/utils";
|
||||
import { tournamentHasStarted } from "~/core/tournament/utils";
|
||||
import { sortTeamsBySeed, tournamentHasStarted } from "~/core/tournament/utils";
|
||||
import {
|
||||
isTournamentAdmin,
|
||||
tournamentHasNotStarted,
|
||||
@@ -91,6 +92,7 @@ export const action: ActionFunction = async ({ context, request }) => {
|
||||
|
||||
export interface SeedsLoaderData {
|
||||
MMRs: Record<string, number>;
|
||||
order: string[];
|
||||
}
|
||||
|
||||
export const loader: LoaderFunction = async ({ params, context }) => {
|
||||
@@ -126,6 +128,7 @@ export const loader: LoaderFunction = async ({ params, context }) => {
|
||||
|
||||
return json<SeedsLoaderData>({
|
||||
MMRs: averageTeamMMRs({ skills, teams: tournament.teams }),
|
||||
order: tournament.seeds,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -136,7 +139,14 @@ export default function TournamentSeedsPage() {
|
||||
const [, parentRoute] = useMatches();
|
||||
const { id, teams } = parentRoute.data as FindTournamentByNameForUrlI;
|
||||
const transition = useTransition();
|
||||
const [teamOrder, setTeamOrder] = React.useState(teams.map((t) => t.id));
|
||||
const [teamOrder, setTeamOrder] = React.useState(
|
||||
clone(teams)
|
||||
// probably this sorting should be redundant but
|
||||
// just in case we sort it here again
|
||||
// (might matter if the order switched after page load e.g.)
|
||||
.sort(sortTeamsBySeed(data.order))
|
||||
.map((t) => t.id)
|
||||
);
|
||||
const [activeTeam, setActiveTeam] = React.useState<Unpacked<
|
||||
FindTournamentByNameForUrlI["teams"]
|
||||
> | null>(null);
|
||||
|
||||
Reference in New Issue
Block a user