From a0bd4d25b1b68d55d8febfcbb16863e38cbe05e5 Mon Sep 17 00:00:00 2001 From: philipcheung Date: Wed, 22 Jan 2025 19:51:29 +0800 Subject: [PATCH] sort course --- frontend/src/client/services.ts | 1 + frontend/src/routes/_layout/Courses/Courses.tsx | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/src/client/services.ts b/frontend/src/client/services.ts index bf35f1c..3806946 100644 --- a/frontend/src/client/services.ts +++ b/frontend/src/client/services.ts @@ -843,6 +843,7 @@ export class Info_imageService { export type TDataReadCourses = { limit?: number skip?: number + sort?: string } export type TDataCreate = { requestBody: CourseCreate diff --git a/frontend/src/routes/_layout/Courses/Courses.tsx b/frontend/src/routes/_layout/Courses/Courses.tsx index 68c42ee..c6f1d0d 100644 --- a/frontend/src/routes/_layout/Courses/Courses.tsx +++ b/frontend/src/routes/_layout/Courses/Courses.tsx @@ -38,7 +38,7 @@ const PER_PAGE = 100 function getcoursesQueryOptions({ page }: { page: number }) { return { queryFn: () => - CoursesService.readCourses({ skip: (page - 1) * PER_PAGE, limit: PER_PAGE }), + CoursesService.readCourses({ skip: (page - 1) * PER_PAGE, limit: PER_PAGE, }), queryKey: ["courses", { page }], } } @@ -59,6 +59,10 @@ function CoursesTable() { } = useQuery({ ...getcoursesQueryOptions({ page }), placeholderData: (prevData) => prevData, + select: (data) => ({ + ...data, + data: [...data.data].sort((a, b) => a.index - b.index) + }) }) const hasNextPage = !isPlaceholderData && courses?.data.length === PER_PAGE