fix polling

This commit is contained in:
x032205
2025-05-06 18:00:24 -04:00
parent 521fef6fca
commit 12c813928c

View File

@@ -14,12 +14,14 @@ export const CachingPanel = () => {
const { mutateAsync: invalidateCache } = useInvalidateCache();
const { user } = useUser();
const shouldShowSuccessRef = useRef(false);
const [type, setType] = useState<CacheType | null>(null);
const [shouldPoll, setShouldPoll] = useState(false);
const { data: invalidationStatus, isPending } = useGetInvalidatingCacheStatus(shouldPoll);
const {
data: invalidationStatus,
isPending,
refetch
} = useGetInvalidatingCacheStatus(shouldPoll);
const isInvalidating = Boolean(shouldPoll && !isPending && invalidationStatus);
const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([
@@ -29,12 +31,16 @@ export const CachingPanel = () => {
const handleInvalidateCacheSubmit = async () => {
if (!type || isInvalidating) return;
shouldShowSuccessRef.current = true;
try {
await invalidateCache({ type });
createNotification({ text: `Began invalidating ${type} cache`, type: "success" });
handlePopUpClose("invalidateCache");
setShouldPoll(true);
refetch().then((v) =>
v
? setShouldPoll(true)
: createNotification({ text: "Successfully invalidated cache", type: "success" })
);
} catch (err) {
console.error(err);
createNotification({ text: `Failed to invalidate ${type} cache`, type: "error" });
@@ -50,6 +56,10 @@ export const CachingPanel = () => {
}
}, [isInvalidating, shouldPoll]);
useEffect(() => {
refetch().then((v) => setShouldPoll(v.data || false));
}, []);
return (
<>
<div className="mb-6 flex flex-wrap items-end justify-between gap-4 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4">