diff --git a/app/components/County.jsx b/app/components/County.jsx
index fe26498..310ca91 100644
--- a/app/components/County.jsx
+++ b/app/components/County.jsx
@@ -1,11 +1,4 @@
-import { useState } from "react";
-
export function County({ county }) {
- const [sort, setSort] = useState({
- field: "rank",
- type: "desc",
- });
-
return (
Place
Player |
-
+ Rank
|
-
+ Score
|
-
+ SS ranks
|
-
+ S ranks
|
-
+ A ranks
|
- {county.players
- .sort((a, b) => {
- if (sort.field === "rank")
- return sort.type === "desc"
- ? parseInt(a.rank) - parseInt(b.rank)
- : parseInt(b.rank) - parseInt(a.rank);
- if (sort.field === "score")
- return sort.type === "desc"
- ? a.score - b.score
- : b.score - a.score;
- if (sort.field === "SS")
- return sort.type === "desc"
- ? a.SSranks - b.SSranks
- : b.SSranks - a.SSranks;
- if (sort.field === "S")
- return sort.type === "desc"
- ? a.Sranks - b.Sranks
- : b.Sranks - a.Sranks;
- if (sort.field === "A")
- return sort.type === "desc"
- ? a.Aranks - b.Aranks
- : b.Aranks - a.Aranks;
- })
- .map((player, index) => (
-
-
- {index + 1}.
- |
-
-
- {player.playerName}
-
- |
-
- {player.rank ? `#${player.rank}` : "-"}
- |
-
- {new Intl.NumberFormat().format(player.score)}
- |
-
- {player.SSranks}
- |
-
- {player.Sranks}
- |
-
- {player.Aranks}
- |
-
- ))}
+ {county.players.map((player, index) => (
+
+
+ {index + 1}.
+ |
+
+
+ {player.playerName}
+
+ |
+
+ {player.rank ? `#${player.rank}` : "-"}
+ |
+
+ {new Intl.NumberFormat().format(player.score)}
+ |
+
+ {player.SSranks}
+ |
+
+ {player.Sranks}
+ |
+
+ {player.Aranks}
+ |
+
+ ))}
) : (
diff --git a/app/routes/index.jsx b/app/routes/index.jsx
index e300884..951a61b 100644
--- a/app/routes/index.jsx
+++ b/app/routes/index.jsx
@@ -110,11 +110,15 @@ export async function action({ request }) {
}
export async function loader({ request }) {
+ const url = new URL(request.url);
+ const toSort = url.searchParams.get("toSort");
+ const type = url.searchParams.get("type");
+
const countyData = await prisma.county.findMany({
include: {
players: {
orderBy: {
- rank: "asc",
+ [toSort ? toSort : "rank"]: type ? type : "asc",
},
},
},