diff --git a/src/pages/benchmarks/index.tsx b/src/pages/benchmarks/index.tsx index 5c9cc83f..c7b9bd23 100644 --- a/src/pages/benchmarks/index.tsx +++ b/src/pages/benchmarks/index.tsx @@ -12,21 +12,50 @@ import $button from "../../components/design_system/button/Button.module.css"; import noBenchmarks from "../../public/img/no-benchmarks.png"; import SearchIcon from "@mui/icons-material/Search"; +type SortProperty = "first_name"; +type SortDirection = "asc" | "desc"; + function Benchmarks() { const [isPara, setIsPara] = useState(false); - const { data: tasks, isLoading } = trpc.para.getMyTasks.useQuery(); + + const [sortProperty, setSortProperty] = useState("first_name"); + const [sortDirection, setSortDirection] = useState("asc"); + + const { data: tasksData, isLoading, error } = trpc.para.getMyTasks.useQuery(); const handleTogglePara = () => { setIsPara(!isPara); }; + const getSortedTasks = () => { + if (!tasksData) return []; + return [...tasksData].sort((a, b) => { + if (a[sortProperty] < b[sortProperty]) + return sortDirection === "asc" ? -1 : 1; + if (a[sortProperty] > b[sortProperty]) + return sortDirection === "asc" ? 1 : -1; + return 0; + }); + }; + + const handleSort = (property: SortProperty) => { + if (property === sortProperty) { + setSortDirection(sortDirection === "asc" ? "desc" : "asc"); + } else { + setSortProperty(property); + setSortDirection("asc"); + } + }; + + const displayedTasks = getSortedTasks(); + if (isLoading) { return
Loading...
; } return ( <> - {tasks?.length === 0 ? ( + {displayedTasks?.length === 0 ? ( Filter - {/* Sort Pill Placeholder*/} + { + // TODO: replace simple sort pill w/this sort pill placeholder + /* + TODO: replace simple sort pill w/this sort pill placeholder + + Sort Pill Placeholder Sort + */ + } + + {/* simple sort pill POC (see TODO above) */} + - {tasks?.map((task) => { + {displayedTasks?.map((task) => { const completed = Math.floor( Number(task.completed_trials) / Number(task.number_of_trials) );