Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/styles/components/toast.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@
padding: 12px 14px;
}

/* 下载通知自带进度条和状态,不需要底部计时条 */
/* 下载通知自带进度条和状态;隐藏计时条但保留动画,自动关闭依赖 animationend */
.Toastify .download-toast .Toastify__progress-bar--wrp {
display: none;
visibility: hidden;
}

/* 服务器没给文件大小时的不确定进度:一段色条来回滑动 */
Expand Down
13 changes: 7 additions & 6 deletions src/utils/download.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ export async function downloadSong(props: DownloadSongParams): Promise<void> {
const toastId = toast.loading(render('loading'), { icon: false, closeButton: false, className: 'download-toast' });

// 进度事件很密集,合并到下一帧再刷新通知
let scheduled = false;
let scheduled: number | undefined;
const refresh = () => {
if (scheduled) return;
scheduled = true;
requestAnimationFrame(() => {
scheduled = false;
if (scheduled !== undefined) return;
scheduled = requestAnimationFrame(() => {
scheduled = undefined;
toast.update(toastId, { render: render('loading') });
});
};
Expand Down Expand Up @@ -98,12 +97,14 @@ export async function downloadSong(props: DownloadSongParams): Promise<void> {

const results = await Promise.all(FILES.map(fetchOne));
const finish = (status: DownloadStatus) => {
// 最后一帧进度不能在完成后把通知改回下载中、覆盖自动关闭设置。
if (scheduled !== undefined) cancelAnimationFrame(scheduled);
toast.update(toastId, {
render: render(status),
type: status === 'done' ? 'success' : 'error',
isLoading: false,
icon: false,
autoClose: status === 'done' ? 3000 : 5000,
autoClose: 5000,
});
};

Expand Down
Loading