fix polling

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