feat: improve toast UX#165
Conversation
… IDs for better status management.
SafeDep Report SummaryNo dependency changes detected. Nothing to scan. This report is generated by SafeDep Github App |
Walkthrough该PR在播放列表同步功能中实现了持久化的toast通知系统。修改涉及多个同步端点(本地、收藏、多页面)添加带ID的持久toast,通过mutation传递toastId以关联toast生命周期,并更新toast工具函数返回值以支持后续的dismiss操作。 Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant UI as 播放列表页面
participant Toast as Toast系统
participant Mutation as Sync Mutation
participant API as 后端API
User->>UI: 点击同步按钮
activate UI
UI->>Toast: toast.show('同步中...', {id: 'sync-playlist', duration: Infinity})
activate Toast
Toast-->>UI: 返回 toastId
deactivate Toast
UI->>Mutation: mutate({remoteSyncId, type, toastId: 'sync-playlist'})
deactivate UI
activate Mutation
Mutation->>API: 发起同步请求
activate API
alt 同步成功
API-->>Mutation: 返回成功结果
Mutation->>Toast: toast.success(..., {id: 'sync-playlist'})
activate Toast
Toast->>Toast: 替换toast为成功状态
deactivate Toast
Mutation->>UI: 导航到本地播放列表
else 同步失败
API-->>Mutation: 返回错误
Mutation->>Toast: toast.dismiss('sync-playlist')
activate Toast
Toast->>Toast: 关闭loading toast
deactivate Toast
Mutation->>Mutation: 记录错误日志
end
deactivate API
deactivate Mutation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
src/app/playlist/remote/favorite/[id].tsx (1)
85-110:setRefreshing(false)执行时机错误导致刷新状态无效。
setRefreshing(false)在 Line 109 同步调用,但syncFavorite是异步操作。这意味着refreshing状态几乎立即被设为false,使得刷新指示器无法正确反映同步进度。🔧 建议的修复方案
const handleSync = useCallback(() => { if (favoriteData?.pages.flatMap((page) => page.medias).length === 0) { toast.info('收藏夹为空,无需同步') return } const toastId = 'sync-playlist' toast.show('同步中...', { id: toastId, duration: Infinity }) setRefreshing(true) syncFavorite( { remoteSyncId: Number(id), type: 'favorite', toastId, }, { onSuccess: (id) => { + setRefreshing(false) if (!id) return router.replace({ pathname: '/playlist/local/[id]', params: { id: String(id) }, }) }, + onError: () => { + setRefreshing(false) + }, }, ) - setRefreshing(false) }, [favoriteData?.pages, id, router, syncFavorite])或者使用
onSettled回调统一处理:syncFavorite( { ... }, { onSuccess: (id) => { ... }, + onSettled: () => { + setRefreshing(false) + }, }, ) - setRefreshing(false)src/app/playlist/remote/collection/[id].tsx (1)
78-99:setRefreshing(false)执行时机错误。与
favorite/[id].tsx存在相同问题:setRefreshing(false)在 Line 98 同步调用,而非等待异步 mutation 完成。🔧 建议的修复方案
const handleSync = useCallback(() => { const toastId = 'sync-playlist' toast.show('同步中...', { id: toastId, duration: Infinity }) setRefreshing(true) syncCollection( { remoteSyncId: Number(id), type: 'collection', toastId, }, { onSuccess: (id) => { + setRefreshing(false) if (!id) return router.replace({ pathname: '/playlist/local/[id]', params: { id: String(id) }, }) }, + onSettled: () => { + setRefreshing(false) + }, }, ) - setRefreshing(false) }, [id, router, syncCollection])src/app/playlist/remote/multipage/[bvid].tsx (1)
101-122:setRefreshing(false)执行时机错误。与
favorite/[id].tsx和collection/[id].tsx存在相同问题。建议统一修复所有三个文件的handleSync回调。🔧 建议的修复方案
const handleSync = useCallback(() => { const toastId = 'sync-playlist' toast.show('同步中...', { id: toastId, duration: Infinity }) setRefreshing(true) syncMultipage( { remoteSyncId: bv2av(bvid), type: 'multi_page', toastId, }, { onSuccess: (id) => { + setRefreshing(false) if (!id) return router.replace({ pathname: '/playlist/local/[id]', params: { id: String(id) }, }) }, + onSettled: () => { + setRefreshing(false) + }, }, ) - setRefreshing(false) }, [bvid, router, syncMultipage])
|
/build-nightly |
⏹️ Nightly 构建已取消构建被新的
|
|
/build-nightly |
✅ Nightly 构建成功
APK 已上传到 Nightly Release 🚀 |
… IDs for better status management.
Summary by CodeRabbit
发布说明
✏️ Tip: You can customize this high-level summary in your review settings.