Skip to content

Commit

Permalink
Fixed modal with tables application crash
Browse files Browse the repository at this point in the history
  • Loading branch information
anderson-oki committed Jan 16, 2025
1 parent e17bad6 commit 4f77710
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 0 additions & 6 deletions frontend/src/components/tables/PageControl.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FunctionComponent } from "react";
import { useSearchParams } from "react-router";
import { Group, Pagination, Text } from "@mantine/core";
import { useIsLoading } from "@/contexts";

Expand All @@ -23,7 +22,6 @@ const PageControl: FunctionComponent<Props> = ({
const end = Math.min(size * (index + 1), total);

const isLoading = useIsLoading();
const [searchParams, setSearchParams] = useSearchParams();

return (
<Group p={16} justify="space-between">
Expand All @@ -35,10 +33,6 @@ const PageControl: FunctionComponent<Props> = ({
color={isLoading ? "gray" : "primary"}
value={index + 1}
onChange={(page) => {
searchParams.set("page", page.toString());

setSearchParams(searchParams, { replace: true });

return goto(page - 1);
}}
hidden={count <= 1}
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/components/tables/QueryPageTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect } from "react";
import { useSearchParams } from "react-router";
import { UsePaginationQueryResult } from "@/apis/queries/hooks";
import SimpleTable, { SimpleTableProps } from "@/components/tables/SimpleTable";
import { LoadingProvider } from "@/contexts";
Expand All @@ -18,6 +19,8 @@ export default function QueryPageTable<T extends object>(props: Props<T>) {
controls: { gotoPage },
} = query;

const [searchParams, setSearchParams] = useSearchParams();

useEffect(() => {
ScrollToTop();
}, [page]);
Expand All @@ -30,7 +33,13 @@ export default function QueryPageTable<T extends object>(props: Props<T>) {
index={page}
size={pageSize}
total={totalCount}
goto={gotoPage}
goto={(page) => {
searchParams.set("page", (page + 1).toString());

setSearchParams(searchParams, { replace: true });

gotoPage(page);
}}
></PageControl>
</LoadingProvider>
);
Expand Down

0 comments on commit 4f77710

Please sign in to comment.