From 9b0ed580518c103dc2560fa4843ed94e24aaa41b Mon Sep 17 00:00:00 2001 From: Manmeet Date: Thu, 1 Jun 2023 10:38:08 +0530 Subject: [PATCH] save the sort in firebase --- src/components/ColumnMenu/ColumnMenu.tsx | 13 +++++----- .../Table/ColumnHeader/ColumnHeaderSort.tsx | 14 +++++----- src/components/TableToolbar/Sort/Sort.tsx | 26 ++++++++++--------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/components/ColumnMenu/ColumnMenu.tsx b/src/components/ColumnMenu/ColumnMenu.tsx index dec3f6fe..d84bd16d 100644 --- a/src/components/ColumnMenu/ColumnMenu.tsx +++ b/src/components/ColumnMenu/ColumnMenu.tsx @@ -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, diff --git a/src/components/Table/ColumnHeader/ColumnHeaderSort.tsx b/src/components/Table/ColumnHeader/ColumnHeaderSort.tsx index 45e924f0..2478ccbd 100644 --- a/src/components/Table/ColumnHeader/ColumnHeaderSort.tsx +++ b/src/components/Table/ColumnHeader/ColumnHeaderSort.tsx @@ -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 ( diff --git a/src/components/TableToolbar/Sort/Sort.tsx b/src/components/TableToolbar/Sort/Sort.tsx index 1ab76a42..9d6d362e 100644 --- a/src/components/TableToolbar/Sort/Sort.tsx +++ b/src/components/TableToolbar/Sort/Sort.tsx @@ -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 }] + ); }} /> @@ -111,7 +110,10 @@ export default function Sort() { setTableSorts([])} + onClick={() => { + setTableSorts([]); + triggerSaveTableSorts([]); + }} sx={{ "&:hover, &:focus": { color: "error.main",