From a19c0641a27a81f3eb9ac56422f52abf3fed4135 Mon Sep 17 00:00:00 2001 From: canjalal Date: Mon, 4 Nov 2024 15:41:52 -0800 Subject: [PATCH] Move types to universal types file --- src/pages/benchmarks/index.tsx | 7 +++---- src/types/global.ts | 3 +++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pages/benchmarks/index.tsx b/src/pages/benchmarks/index.tsx index c7b9bd23..f4081477 100644 --- a/src/pages/benchmarks/index.tsx +++ b/src/pages/benchmarks/index.tsx @@ -11,9 +11,7 @@ import { useState } from "react"; 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"; +import { SortDirection, SortProperty } from "@/types/global"; function Benchmarks() { const [isPara, setIsPara] = useState(false); @@ -21,7 +19,7 @@ function Benchmarks() { const [sortProperty, setSortProperty] = useState("first_name"); const [sortDirection, setSortDirection] = useState("asc"); - const { data: tasksData, isLoading, error } = trpc.para.getMyTasks.useQuery(); + const { data: tasksData, isLoading } = trpc.para.getMyTasks.useQuery(); const handleTogglePara = () => { setIsPara(!isPara); @@ -29,6 +27,7 @@ function Benchmarks() { const getSortedTasks = () => { if (!tasksData) return []; + return [...tasksData].sort((a, b) => { if (a[sortProperty] < b[sortProperty]) return sortDirection === "asc" ? -1 : 1; diff --git a/src/types/global.ts b/src/types/global.ts index ed7f1091..2f4081ea 100644 --- a/src/types/global.ts +++ b/src/types/global.ts @@ -4,3 +4,6 @@ export type Goal = SelectableForTable<"goal">; export type Benchmark = SelectableForTable<"benchmark">; export type ChangeEvent = React.ChangeEvent; export type FormEvent = React.FormEvent; + +export type SortProperty = "first_name"; +export type SortDirection = "asc" | "desc";