Sort by premium when the order type is defined #2146

This commit is contained in:
Lucas Jeffrey
2025-08-25 23:12:06 -03:00
parent a84bc4f143
commit 963b31604c

View File

@ -1,4 +1,4 @@
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
import React, { useCallback, useContext, useEffect, useMemo, useState, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import {
Box,
@ -774,6 +774,22 @@ const BookTable = ({
: orders;
}, [showControls, orders, fav, paymentMethods]);
const currentSortModel = useMemo(() => {
if (fav.type === 1) {
// buyer
return [{field: 'premium', sort: 'asc'}];
} else if (fav.type === 0) {
// seller
return [{field: 'premium', sort: 'desc'}];
} else {
return undefined;
}
}, [fav]);
const prevSortModel = useRef<number | undefined>();
const sortModel = prevSortModel.current !== fav.type ? currentSortModel : undefined;
prevSortModel.current = fav.type;
if (!fullscreen) {
return (
<Paper
@ -798,6 +814,7 @@ const BookTable = ({
sx={headerStyleFix}
localeText={localeText}
rows={filteredOrders}
sortModel={sortModel}
getRowId={(params: PublicOrder) => `${String(params.coordinatorShortAlias)}/${params.id}`}
loading={federation.loading}
columns={columns}
@ -840,6 +857,7 @@ const BookTable = ({
rows={filteredOrders}
loading={federation.loading}
columns={columns}
sortModel={sortModel}
hideFooter={!showFooter}
slots={gridComponents}
page={page}