mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-25 01:57:06 +00:00
fix(ui): apply initial progress state on mount to prevent 0% blink
This commit is contained in:
@@ -55,10 +55,8 @@ export const DownloadItem = React.memo<DownloadItemProps>(({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!download || download.status !== 'downloading') return;
|
if (!download || download.status !== 'downloading') return;
|
||||||
|
|
||||||
const unsubscribe = useDownloadProgressStore.subscribe((state) => {
|
const applyProgress = (progress: any) => {
|
||||||
const progress = state.progressMap[downloadId];
|
|
||||||
if (!progress) return;
|
if (!progress) return;
|
||||||
|
|
||||||
if (progressBarRef.current) {
|
if (progressBarRef.current) {
|
||||||
progressBarRef.current.style.width = `${progress.fraction * 100}%`;
|
progressBarRef.current.style.width = `${progress.fraction * 100}%`;
|
||||||
}
|
}
|
||||||
@@ -74,6 +72,13 @@ export const DownloadItem = React.memo<DownloadItemProps>(({
|
|||||||
etaTextRef.current.innerText = progress.eta;
|
etaTextRef.current.innerText = progress.eta;
|
||||||
etaTextRef.current.title = progress.eta;
|
etaTextRef.current.title = progress.eta;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Apply immediate state on mount
|
||||||
|
applyProgress(useDownloadProgressStore.getState().progressMap[downloadId]);
|
||||||
|
|
||||||
|
const unsubscribe = useDownloadProgressStore.subscribe((state) => {
|
||||||
|
applyProgress(state.progressMap[downloadId]);
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => unsubscribe();
|
return () => unsubscribe();
|
||||||
|
|||||||
Reference in New Issue
Block a user