refactor: pass isFetching as prop to WidgetCacheAge to avoid duplicate useIsFetching
This commit is contained in:
1 parent
d9873355b7
commit
bbebf494bb
1 file changed
+11
-4
@@ -232,7 +232,7 @@ export const WidgetContextMenu = ({ item, widgetStateRef, children }: WidgetCont
|
|||||||
<Group justify="space-between" wrap="nowrap">
|
<Group justify="space-between" wrap="nowrap">
|
||||||
{tMenu("refresh")}
|
{tMenu("refresh")}
|
||||||
<Text size="xs" c="dimmed">
|
<Text size="xs" c="dimmed">
|
||||||
<WidgetCacheAge queryClient={queryClient} queryKey={widgetQueryKey} />
|
<WidgetCacheAge queryClient={queryClient} queryKey={widgetQueryKey} isFetching={isWidgetFetching} />
|
||||||
</Text>
|
</Text>
|
||||||
</Group>
|
</Group>
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
@@ -270,9 +270,16 @@ export const WidgetContextMenu = ({ item, widgetStateRef, children }: WidgetCont
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const WidgetCacheAge = ({ queryClient, queryKey }: { queryClient: QueryClient; queryKey: unknown[] }) => {
|
const WidgetCacheAge = ({
|
||||||
const isFetching = useIsFetching({ queryKey }) > 0;
|
queryClient,
|
||||||
// ponytail: 1s tick for "just now" → "1s ago" transition; useIsFetching handles refetch reactivity
|
queryKey,
|
||||||
|
isFetching,
|
||||||
|
}: {
|
||||||
|
queryClient: QueryClient;
|
||||||
|
queryKey: unknown[];
|
||||||
|
isFetching: boolean;
|
||||||
|
}) => {
|
||||||
|
// 1s tick for "just now" → "1s ago" label transition; isFetching prop handles refetch reactivity
|
||||||
const [, setTick] = useState(0);
|
const [, setTick] = useState(0);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const id = setInterval(() => setTick((n) => n + 1), 1000);
|
const id = setInterval(() => setTick((n) => n + 1), 1000);
|
||||||
|
|||||||
Reference in new issue
Block a user