feat(KB-650): add refresh-on-open effect to usage modal

- Add refresh effect when usage modal opens to get latest usage data\n- Include changeset for usage modal refresh feature
This commit is contained in:
gsxdsm
2026-03-31 23:22:04 -07:00
parent 552ba8db2d
commit 560bb3a1aa
2 changed files with 20 additions and 0 deletions

View File

@@ -241,6 +241,21 @@ export function UsageIndicator({ isOpen, onClose }: UsageIndicatorProps) {
const [isRefreshing, setIsRefreshing] = useState(false);
const [viewMode, setViewMode] = useState<'used' | 'remaining'>('used');
const contentRef = useRef<HTMLDivElement>(null);
const wasOpenRef = useRef(isOpen);
// Trigger refresh when modal opens (isOpen transitions from false to true)
useEffect(() => {
// Only refresh when transitioning from closed to open
if (!wasOpenRef.current && isOpen) {
// Skip if data is fresh (within 5 seconds) to avoid duplicate requests
if (!lastUpdated || Date.now() - lastUpdated.getTime() > 5000) {
refresh();
}
}
// Update ref for next render
wasOpenRef.current = isOpen;
}, [isOpen, lastUpdated, refresh]);
// Load view mode preference from localStorage on mount
useEffect(() => {