Skip to content

Commit

Permalink
Fix searchbar bug
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAndrewJackson committed Dec 1, 2023
1 parent e0eff6d commit 981d86a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ export const useClientSidePagination = <T,>(
};

export const useServerSidePagination = () => {
const defaultPageIndex = 1;
const [pageSize, setPageSize] = useState(PAGE_SIZES[0]);
const [pageIndex, setPageIndex] = useState<number>(1);
const [pageIndex, setPageIndex] = useState<number>(defaultPageIndex);
const [totalPages, setTotalPages] = useState<number>();
const onPreviousPageClick = useCallback(() => {
setPageIndex((prev) => prev - 1);
Expand All @@ -61,6 +62,10 @@ export const useServerSidePagination = () => {
(pageIndex - 1) * pageSize === 0 ? 1 : (pageIndex - 1) * pageSize;
const endRange = (pageIndex - 1) * pageSize + pageSize;

const resetPageIndexToDefault = () => {
setPageIndex(defaultPageIndex);
};

return {
onPreviousPageClick,
isPreviousPageDisabled,
Expand All @@ -72,6 +77,7 @@ export const useServerSidePagination = () => {
startRange,
endRange,
pageIndex,
resetPageIndexToDefault,
setTotalPages,
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const emptyVendorReportResponse: Page_SystemSummary_ = {
export const ConsentManagementTable = () => {
const { tcf: isTcfEnabled } = useFeatures();
const { isLoading: isLoadingHealthCheck } = useGetHealthQuery();
const [globalFilter, setGlobalFilter] = useState();

const {
isOpen: isFilterOpen,
Expand Down Expand Up @@ -110,9 +109,17 @@ export const ConsentManagementTable = () => {
startRange,
endRange,
pageIndex,
resetPageIndexToDefault,
setTotalPages,
} = useServerSidePagination();

const [globalFilter, setGlobalFilter] = useState<string>();

const updateGlobalFilter = (searchTerm: string) => {
resetPageIndexToDefault();
setGlobalFilter(searchTerm);
};

const {
isFetching: isReportFetching,
isLoading: isReportLoading,
Expand Down Expand Up @@ -223,7 +230,7 @@ export const ConsentManagementTable = () => {
<TableActionBar>
<GlobalFilterV2
globalFilter={globalFilter}
setGlobalFilter={setGlobalFilter}
setGlobalFilter={updateGlobalFilter}
placeholder="Search"
/>
<ConsentManagementFilterModal
Expand Down

0 comments on commit 981d86a

Please sign in to comment.