feat: implement rate limiting handling in JMAPClient #104

This commit is contained in:
Linus Rath
2026-03-27 00:22:40 +01:00
parent 6696636df8
commit a46fb9c8af
17 changed files with 481 additions and 67 deletions
@@ -0,0 +1,30 @@
"use client";
import { useEffect } from 'react';
import { useTranslations } from 'next-intl';
import { toast } from '@/stores/toast-store';
type RateLimitBlockedDetail = {
retryAfterMs?: number;
};
export function RateLimitToastProvider({ children }: { children: React.ReactNode }) {
const tCommon = useTranslations('common');
useEffect(() => {
const onRateLimitBlocked = (event: Event) => {
const detail = (event as CustomEvent<RateLimitBlockedDetail>).detail;
const seconds = Math.max(1, Math.ceil((detail?.retryAfterMs ?? 0) / 1000));
toast.warning(
tCommon('rate_limited_action_title'),
tCommon('rate_limited_action_detail', { seconds }),
);
};
window.addEventListener('bulwark:rate-limit-blocked', onRateLimitBlocked);
return () => window.removeEventListener('bulwark:rate-limit-blocked', onRateLimitBlocked);
}, [tCommon]);
return <>{children}</>;
}