Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
refetch user quota once in 10 minutes and on code studio open
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiya1155 committed Sep 12, 2023
1 parent dbcc0a3 commit f1b841d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 11 additions & 1 deletion client/src/context/providers/PersonalQuotaContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,24 @@ 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);
});
}, []);

useEffect(() => {
refetchQuota();
const intervalId = setInterval(() => refetchQuota(), 10 * 60 * 1000);
return () => {
clearInterval(intervalId);
};
}, [refetchQuota]);

const contextValue = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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[] = [
Expand Down

0 comments on commit f1b841d

Please sign in to comment.