Files
real-time-fund/app/components/RefreshButton.jsx
2026-02-27 21:01:09 +08:00

41 lines
1.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use client';
import { useEffect, useState } from "react";
import { RefreshIcon } from './Icons';
export default function RefreshButton({ refreshCycleStartRef, refreshMs, manualRefresh, refreshing, fundsLength }) {
// 刷新周期进度 0~1用于环形进度条
const [refreshProgress, setRefreshProgress] = useState(0);
// 刷新进度条:每 100ms 更新一次进度
useEffect(() => {
if (fundsLength === 0 || refreshMs <= 0) return;
const t = setInterval(() => {
const elapsed = Date.now() - refreshCycleStartRef.current;
const p = Math.min(1, elapsed / refreshMs);
setRefreshProgress(p);
}, 100);
return () => clearInterval(t);
}, [fundsLength, refreshMs]);
return (
<div
className="refresh-btn-wrap"
style={{ '--progress': refreshProgress }}
title={`刷新周期 ${Math.round(refreshMs / 1000)}`}
>
<button
className="icon-button"
aria-label="立即刷新"
onClick={manualRefresh}
disabled={refreshing || fundsLength === 0}
aria-busy={refreshing}
title="立即刷新"
>
<RefreshIcon className={refreshing ? 'spin' : ''} width="18" height="18" />
</button>
</div>
);
}