mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
fix polling
This commit is contained in:
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user