Skip to content

Commit d1d8164

Browse files
committed
move refetch on page change to upper component
1 parent 4c1a68c commit d1d8164

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/Serilog.Ui.Web/src/app/components/Search/PagingRightColumn.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import { useDisclosure, useMediaQuery } from '@mantine/hooks';
1313
import { IconBook, IconListNumbers } from '@tabler/icons-react';
1414
import useQueryLogs from 'app/hooks/useQueryLogs';
1515
import { toNumber } from 'app/util/guards';
16-
import { memo, useEffect, useMemo, useState } from 'react';
16+
import { memo, useMemo, useState } from 'react';
1717
import { ControllerRenderProps, FieldValues } from 'react-hook-form';
1818
import classes from 'style/search.module.css';
1919

2020
export const PagingRightColumn = memo(
2121
({ field }: { field: ControllerRenderProps<FieldValues, 'page'> }) => {
2222
const [opened, { close, toggle }] = useDisclosure(false);
2323

24-
const { data, refetch } = useQueryLogs();
24+
const { data } = useQueryLogs();
2525

2626
const lessPages = useMediaQuery(`(max-width: ${em(800)})`);
2727
const totalPages = useMemo(() => {
@@ -30,10 +30,6 @@ export const PagingRightColumn = memo(
3030
return Number.isNaN(pages) ? 1 : pages;
3131
}, [data]);
3232

33-
useEffect(() => {
34-
void refetch();
35-
}, [refetch, field.value]);
36-
3733
return (
3834
<Box
3935
className={classes.paginationGrid}

src/Serilog.Ui.Web/src/app/components/Search/Search.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { useQueryTableKeys } from 'app/hooks/useQueryTableKeys';
1515
import { useSearchForm } from 'app/hooks/useSearchForm';
1616
import { useSerilogUiProps } from 'app/hooks/useSerilogUiProps';
1717
import { memo, useEffect } from 'react';
18-
import { useController } from 'react-hook-form';
18+
import { useController, useWatch } from 'react-hook-form';
1919
import classes from 'style/search.module.css';
2020
import { LogLevel } from '../../../types/types';
2121

@@ -27,10 +27,11 @@ const levelsArray = Object.keys(LogLevel).map((level) => ({
2727
const Search = ({ onRefetch }: { onRefetch?: () => void }) => {
2828
const { isError } = useQueryTableKeys(true);
2929
const { isUtc, setIsUtc } = useSerilogUiProps();
30-
const { handleSubmit, reset, setValue, watch } = useSearchForm();
30+
const { handleSubmit, reset, setValue } = useSearchForm();
3131

3232
const { refetch } = useQueryLogs();
33-
const currentDbKey = watch('table');
33+
const currentDbKey = useWatch({ name: 'table' });
34+
const currentPage = useWatch({ name: 'page' });
3435

3536
const clean = async () => {
3637
reset();
@@ -45,7 +46,7 @@ const Search = ({ onRefetch }: { onRefetch?: () => void }) => {
4546

4647
useEffect(() => {
4748
void refetch();
48-
}, [currentDbKey, refetch]);
49+
}, [currentDbKey, currentPage, refetch]);
4950

5051
return (
5152
<form aria-label="search-logs-form" onSubmit={() => {}}>

0 commit comments

Comments
 (0)