fix(web): make cancel, delete and chat work while a file is uploading [CI]
This commit is contained in:
1 parent
1245aedfd2
commit
7ef298f587
4 files changed
+34
-6
No files matched your search
@@ -63,7 +63,7 @@ interface Actions {
|
||||
/** 重试发送失败的本地占位项 */
|
||||
retrySend: (localId: string) => Promise<void>;
|
||||
/** 取消排队中或上传中的文件 */
|
||||
cancelUpload: (localId: string) => Promise<void>;
|
||||
cancelUpload: (localId: string, itemId?: string) => Promise<void>;
|
||||
updateChannelSettings: (patch: ChannelSettingsPatch) => Promise<void>;
|
||||
sendFiles: (files: File[], options?: FileUploadOptions, threadId?: string, folderId?: string) => Promise<void>;
|
||||
createThread: (name: string, groupId?: string) => Promise<string>;
|
||||
@@ -105,10 +105,12 @@ export const useWorkspace = create<WorkspaceData & Actions>()(() => ({
|
||||
return deliver(id);
|
||||
},
|
||||
retrySend: (id) => deliver(id),
|
||||
cancelUpload: async (localId) => {
|
||||
cancelUpload: async (localId, itemId) => {
|
||||
pendingJobs.delete(localId);
|
||||
useWorkspace.setState((s) => withoutItem(s, localId));
|
||||
await api.cancelUpload(localId).catch(() => false);
|
||||
const found = await api.cancelUpload(localId).catch(() => false);
|
||||
// worker 里没有这个任务(上次会话遗留的半截上传):当普通条目删除
|
||||
if (!found && itemId) { useWorkspace.setState((s) => withoutItem(s, itemId)); await api.remove(itemId).catch(() => undefined); }
|
||||
},
|
||||
updateChannelSettings: (patch) => api.updateChannelSettings(patch),
|
||||
sendFiles: async (files, options, threadId, folderId) => {
|
||||
@@ -139,7 +141,13 @@ export const useWorkspace = create<WorkspaceData & Actions>()(() => ({
|
||||
moveItems: (itemIds, threadId, folderId) => api.moveItems(itemIds, threadId, folderId),
|
||||
editText: (id, t): Promise<void> => api.editText(id, t, useWorkspace.getState().byId[id]?.threadId),
|
||||
resolveConflict: (id, c) => api.resolveConflict(id, c),
|
||||
remove: (id) => { if (!pendingJobs.has(id)) return api.remove(id); settleLocal(id); return Promise.resolve(); },
|
||||
remove: async (id) => {
|
||||
if (pendingJobs.has(id)) { settleLocal(id); await api.cancelUpload(id).catch(() => false); return; }
|
||||
const item = useWorkspace.getState().byId[id];
|
||||
// 还在上传的文件:删除就是取消(先停掉上传,否则后面的帧会打到已删除的条目上)
|
||||
if (item?.kind === 'file' && item.state.kind === 'receiving') { await useWorkspace.getState().cancelUpload(item.localId ?? id, id); return; }
|
||||
await api.remove(id);
|
||||
},
|
||||
setSnapshot: (t) => api.setSnapshot(t),
|
||||
getBlob: (id, v) => api.getBlob(id, v),
|
||||
markSeen: (id) => api.markSeen(id),
|
||||
|
||||
Reference in new issue
Block a user