save the sort in firebase

This commit is contained in:
Manmeet
2023-06-01 10:38:08 +05:30
parent 316807a0ed
commit 9b0ed58051
3 changed files with 27 additions and 26 deletions

View File

@@ -192,9 +192,10 @@ export default function ColumnMenu({
setTableSorts(
isSorted && !isAsc ? [] : [{ key: sortKey, direction: "desc" }]
);
if (!isSorted || isAsc) {
triggerSaveTableSorts([{ key: sortKey, direction: "desc" }]);
}
triggerSaveTableSorts(
isSorted && !isAsc ? [] : [{ key: sortKey, direction: "desc" }]
);
handleClose();
},
active: isSorted && !isAsc,
@@ -209,9 +210,9 @@ export default function ColumnMenu({
setTableSorts(
isSorted && isAsc ? [] : [{ key: sortKey, direction: "asc" }]
);
if (!isSorted || !isAsc) {
triggerSaveTableSorts([{ key: sortKey, direction: "asc" }]);
}
triggerSaveTableSorts(
isSorted && isAsc ? [] : [{ key: sortKey, direction: "asc" }]
);
handleClose();
},
active: isSorted && isAsc,

View File

@@ -38,14 +38,12 @@ export const ColumnHeaderSort = memo(function ColumnHeaderSort({
const triggerSaveTableSorts = useSaveTableSorts(canEditColumns);
const handleSortClick = () => {
if (nextSort === "none") setTableSorts([]);
else setTableSorts([{ key: sortKey, direction: nextSort }]);
triggerSaveTableSorts([
{
key: sortKey,
direction: nextSort === "none" ? "asc" : nextSort,
},
]);
setTableSorts(
nextSort === "none" ? [] : [{ key: sortKey, direction: nextSort }]
);
triggerSaveTableSorts(
nextSort === "none" ? [] : [{ key: sortKey, direction: nextSort }]
);
};
return (

View File

@@ -57,17 +57,16 @@ export default function Sort() {
options={sortColumns}
value={tableSorts[0].key}
onChange={(value: string | null) => {
if (value) {
setTableSorts([
{ key: value, direction: tableSorts[0].direction },
]);
triggerSaveTableSorts([
{ key: value, direction: tableSorts[0].direction },
]);
} else {
setTableSorts([]);
}
setTableSorts(
value === null
? []
: [{ key: value, direction: tableSorts[0].direction }]
);
triggerSaveTableSorts(
value === null
? []
: [{ key: value, direction: tableSorts[0].direction }]
);
}}
/>
</Grid>
@@ -111,7 +110,10 @@ export default function Sort() {
<Grid item xs={1} alignSelf="flex-end">
<IconButton
size="small"
onClick={() => setTableSorts([])}
onClick={() => {
setTableSorts([]);
triggerSaveTableSorts([]);
}}
sx={{
"&:hover, &:focus": {
color: "error.main",