diff --git a/client/src/context/providers/PersonalQuotaContextProvider.tsx b/client/src/context/providers/PersonalQuotaContextProvider.tsx index 63d650e369..3170d39ded 100644 --- a/client/src/context/providers/PersonalQuotaContextProvider.tsx +++ b/client/src/context/providers/PersonalQuotaContextProvider.tsx @@ -21,7 +21,13 @@ export const PersonalQuotaContextProvider = memo( const refetchQuota = useCallback(() => { getQuota().then((resp) => { setIsSubscribed(resp.upgraded); - setQuota({ used: resp.used, allowed: resp.allowed }); + setQuota((prev) => { + const newState = { used: resp.used, allowed: resp.allowed }; + if (JSON.stringify(prev) === JSON.stringify(newState)) { + return prev; + } + return newState; + }); setRequestsLeft(Math.max(resp.allowed - resp.used, 0)); setHasCheckedQuota(true); }); @@ -29,6 +35,10 @@ export const PersonalQuotaContextProvider = memo( useEffect(() => { refetchQuota(); + const intervalId = setInterval(() => refetchQuota(), 10 * 60 * 1000); + return () => { + clearInterval(intervalId); + }; }, [refetchQuota]); const contextValue = useMemo( diff --git a/client/src/pages/HomeTab/CodeStudiosSection/CodeStudioCard.tsx b/client/src/pages/HomeTab/CodeStudiosSection/CodeStudioCard.tsx index a9000e4de5..91d226be47 100644 --- a/client/src/pages/HomeTab/CodeStudiosSection/CodeStudioCard.tsx +++ b/client/src/pages/HomeTab/CodeStudiosSection/CodeStudioCard.tsx @@ -17,6 +17,7 @@ import { ContextMenuItem } from '../../../components/ContextMenu'; import { deleteCodeStudio } from '../../../services/api'; import FileIcon from '../../../components/FileIcon'; import LiteLoaderContainer from '../../../components/Loaders/LiteLoader'; +import { PersonalQuotaContext } from '../../../context/personalQuotaContext'; type Props = { modified_at: string; @@ -42,14 +43,16 @@ const CodeStudioCard = ({ const { t } = useTranslation(); const { locale } = useContext(LocaleContext); const { handleAddStudioTab, handleRemoveTab } = useContext(TabsContext); + const { refetchQuota } = useContext(PersonalQuotaContext.Handlers); const handleClick = useCallback(() => { if (!isIndexing) { handleAddStudioTab(name, id); + refetchQuota(); } else { showCodeStudioIndexingPopup(); } - }, [name, handleAddStudioTab, isIndexing]); + }, [name, handleAddStudioTab, isIndexing, refetchQuota]); const dropdownItems = useMemo(() => { const items: ContextMenuItem[] = [