diff --git a/packages/api-react/src/hooks/useGetThrottlePlotQueueQuery.ts b/packages/api-react/src/hooks/useGetThrottlePlotQueueQuery.ts index 03cead0a88..f1d9ffa800 100644 --- a/packages/api-react/src/hooks/useGetThrottlePlotQueueQuery.ts +++ b/packages/api-react/src/hooks/useGetThrottlePlotQueueQuery.ts @@ -1,5 +1,7 @@ import { PlotQueueItem } from '@chia-network/api'; +import { useEffect, useMemo } from 'react'; +import { useRefreshPlotsMutation } from '../services/harvester'; import { useGetPlotQueueQuery } from '../services/plotter'; import useThrottleQuery from './useThrottleQuery'; @@ -16,6 +18,18 @@ export default function useGetThrottlePlotQueueQuery(wait = 5000): { } = useThrottleQuery(useGetPlotQueueQuery, undefined, undefined, { wait, }); + const [refreshPlots] = useRefreshPlotsMutation(); + + const finished = useMemo(() => queue?.filter((item: PlotQueueItem) => item.state === 'FINISHED'), [queue]); + + const finishedLength = finished?.length || 0; + + // refetch plots query when new plot is finished plotting + useEffect(() => { + if (finishedLength > 0) { + refreshPlots().unwrap(); + } + }, [finishedLength, refreshPlots]); return { queue,