From 7949218076b5271deb1e5cad4bda444d5b3ba60c Mon Sep 17 00:00:00 2001 From: NilsUeter Date: Sun, 27 Apr 2025 17:20:45 +0200 Subject: [PATCH] add manual sorting to unit cards --- src/10th/Roster.jsx | 115 +++++++++++++++++++++++++-------- src/10th/ShortSummaryTable.jsx | 2 +- src/index.css | 21 +++--- 3 files changed, 102 insertions(+), 36 deletions(-) diff --git a/src/10th/Roster.jsx b/src/10th/Roster.jsx index edaa33e..4a20fc5 100644 --- a/src/10th/Roster.jsx +++ b/src/10th/Roster.jsx @@ -60,14 +60,20 @@ export const Roster = ({ const Force = ({ force, onePerPage, colorUserChoice }) => { const { units, factionRules, rules, catalog } = force; const mergedRules = new Map([...factionRules, ...rules]); - // units with role "Character" are sorted to the top, then "Battleline", then "Other" - const sortedUnits = units.sort((a, b) => { - if (a.role === "Character" && b.role !== "Character") return -1; - if (a.role !== "Character" && b.role === "Character") return 1; - if (a.role === "Battleline" && b.role !== "Battleline") return -1; - if (a.role !== "Battleline" && b.role === "Battleline") return 1; - return a.name.localeCompare(b.name); - }); + + // State to manage the order of units + const [unitOrder, setUnitOrder] = useState([]); + + useEffect(() => { + const sortedUnits = units.sort((a, b) => { + if (a.role === "Character" && b.role !== "Character") return -1; + if (a.role !== "Character" && b.role === "Character") return 1; + if (a.role === "Battleline" && b.role !== "Battleline") return -1; + if (a.role !== "Battleline" && b.role === "Battleline") return 1; + return a.name.localeCompare(b.name); + }); + setUnitOrder(sortedUnits); + }, [units]); return (
{ display: "contents", }} > - {sortedUnits.map((unit, index) => ( - + {unitOrder.map((unit, index) => ( +
+
+ + +
+ +
))}
); }; -const Unit = ({ - unit, - index, - catalog, - onePerPage, - forceRules, - colorUserChoice, -}) => { +const Unit = ({ unit, catalog, onePerPage, forceRules, colorUserChoice }) => { const [hide, setHide] = useState(false); const [hideModelCount, setHideModelCount] = useState(false); const uploadRef = useRef(); diff --git a/src/10th/ShortSummaryTable.jsx b/src/10th/ShortSummaryTable.jsx index 7a1e7e3..134a0b2 100644 --- a/src/10th/ShortSummaryTable.jsx +++ b/src/10th/ShortSummaryTable.jsx @@ -24,7 +24,7 @@ export const ShortSummaryTable = ({ force, primaryColor, name, points }) => { const [hide, setHide] = useState(false); const { units, factionRules, rules, catalog } = force; - const sortedUnits = units.sort((a, b) => { + const sortedUnits = units.slice().sort((a, b) => { // sort by points cost desc first, then by name if (a.cost.points < b.cost.points) return 1; if (a.cost.points > b.cost.points) return -1; diff --git a/src/index.css b/src/index.css index b55ad7f..82b7e1d 100644 --- a/src/index.css +++ b/src/index.css @@ -4,9 +4,8 @@ @layer base { :root { - font-family: - "Noto Sans", sans-serif, Inter, system-ui, Avenir, Helvetica, Arial, - sans-serif; + font-family: "Noto Sans", sans-serif, Inter, system-ui, Avenir, Helvetica, + Arial, sans-serif; line-height: 1.5; font-weight: 400; font-size: 13px; @@ -80,7 +79,7 @@ font-weight: 500; font-family: inherit; cursor: pointer; - transition: border-color 0.25s; + transition: border-color 0.15s; } button:hover, .button:hover { @@ -94,6 +93,13 @@ outline: 4px auto -webkit-focus-ring-color; } + button:disabled, + .button[disabled] { + background-color: #f0f0f0; + color: #999; + border-color: #999; + } + .body { display: flex; flex-direction: column; @@ -139,11 +145,8 @@ font-size: 1.5rem; text-transform: uppercase; cursor: pointer; - transition: - color 0.25s, - border 0.25s, - font-size 0.25s, - background-color 0.25s; + transition: color 0.15s, border 0.15s, font-size 0.15s, background-color + 0.15s; } .rosterUpload:hover {