Skip to content

Commit f4620fa

Browse files
committed
fix: table width keeps changing and incorrect question complexity sort
1 parent 5240690 commit f4620fa

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

project/apps/web/app/questions/page.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
getPaginationRowModel,
2626
getSortedRowModel,
2727
flexRender,
28+
SortingFn,
2829
} from "@tanstack/react-table";
2930
import {
3031
Table,
@@ -89,6 +90,19 @@ export default function QuestionRepositoryContent() {
8990
{ value: CATEGORY.Arrays, label: "Arrays" },
9091
{ value: CATEGORY.Recursion, label: "Recursion" },
9192
];
93+
const complexityOrder: { [key in COMPLEXITY]: number } = {
94+
[COMPLEXITY.Easy]: 1,
95+
[COMPLEXITY.Medium]: 2,
96+
[COMPLEXITY.Hard]: 3,
97+
};
98+
99+
// To sort the questions by complexity level
100+
const complexitySortingFn: SortingFn<QuestionDto> = (rowA, rowB, columnId) => {
101+
const valueA = rowA.getValue(columnId) as COMPLEXITY;
102+
const valueB = rowB.getValue(columnId) as COMPLEXITY;
103+
104+
return complexityOrder[valueA] - complexityOrder[valueB];
105+
};
92106

93107
// Define columns with filtering and sorting
94108
const complexityFilter = (row: any, columnId: string, filterValue: string[]) => { //TODO: row : any
@@ -143,6 +157,7 @@ export default function QuestionRepositoryContent() {
143157
<DifficultyBadge complexity={row.original.q_complexity} />
144158
),
145159
filterFn: complexityFilter,
160+
sortingFn: complexitySortingFn,
146161
},
147162
{
148163
accessorKey: "q_category",
@@ -239,7 +254,7 @@ export default function QuestionRepositoryContent() {
239254
<EmptyPlaceholder />
240255
) : (
241256
<div className="rounded-md border">
242-
<Table>
257+
<Table className="table-fixed">
243258
<TableHeader>
244259
{table.getHeaderGroups().map((headerGroup) => (
245260
<TableRow key={headerGroup.id}>

0 commit comments

Comments
 (0)