fix: sort in desc based update date by default (#2510)

This commit is contained in:
Whitewater 2023-05-25 00:33:02 -07:00 committed by GitHub
parent 675c737e48
commit be065e2de3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -117,7 +117,7 @@ export const PageList = ({
}: PageListProps) => {
const sorter = useSorter<ListData>({
data: list,
key: 'createDate',
key: 'updatedDate',
order: 'desc',
});

View File

@ -9,7 +9,7 @@ type SorterConfig<T> = {
const defaultSortingFn = <T extends Record<keyof any, unknown>>(
ctx: {
key: keyof T;
order: 'asc' | 'desc' | 'none';
order: 'asc' | 'desc';
},
a: T,
b: T
@ -21,10 +21,10 @@ const defaultSortingFn = <T extends Record<keyof any, unknown>>(
return 0;
}
if (typeof valA === 'string') {
return valA.localeCompare(valB as string) * (revert ? 1 : -1);
return valA.localeCompare(valB as string) * (revert ? -1 : 1);
}
if (typeof valA === 'number') {
return valA - (valB as number) * (revert ? 1 : -1);
return valA - (valB as number) * (revert ? -1 : 1);
}
return 0;
};