Skip to content

Commit 598c956

Browse files
committed
ui(server): fix file uploads being canceled instead of completed
1 parent 158facd commit 598c956

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

resources/scripts/components/server/files/FileManagerStatus.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const Spinner = ({ progress, className }: { progress: number; className?: string
3232

3333
const FileUploadList = () => {
3434
const { close } = useContext(DialogWrapperContext);
35-
const removeFileUpload = ServerContext.useStoreActions((actions) => actions.files.removeFileUpload);
35+
const cancelFileUpload = ServerContext.useStoreActions((actions) => actions.files.cancelFileUpload);
3636
const clearFileUploads = ServerContext.useStoreActions((actions) => actions.files.clearFileUploads);
3737
const uploads = ServerContext.useStoreState((state) =>
3838
Object.entries(state.files.uploads).sort(([a], [b]) => a.localeCompare(b))
@@ -49,7 +49,7 @@ const FileUploadList = () => {
4949
</Tooltip>
5050
<Code className={'flex-1 truncate'}>{name}</Code>
5151
<button
52-
onClick={removeFileUpload.bind(this, name)}
52+
onClick={cancelFileUpload.bind(this, name)}
5353
className={'text-gray-500 hover:text-gray-200 transition-colors duration-75'}
5454
>
5555
<XIcon className={'w-5 h-5'} />

resources/scripts/components/server/files/UploadButton.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ export default ({ className }: WithClassname) => {
5959

6060
const onUploadProgress = (data: ProgressEvent, name: string) => {
6161
setUploadProgress({ name, loaded: data.loaded });
62-
if (data.loaded >= data.total) {
63-
timeouts.value.push(setTimeout(() => removeFileUpload(name), 500));
64-
}
6562
};
6663

6764
const onFileSubmission = (files: FileList) => {
@@ -73,20 +70,25 @@ export default ({ className }: WithClassname) => {
7370

7471
const uploads = list.map((file) => {
7572
const controller = new AbortController();
76-
pushFileUpload({ name: file.name, data: { abort: controller, loaded: 0, total: file.size } });
73+
pushFileUpload({
74+
name: file.name,
75+
data: { abort: controller, loaded: 0, total: file.size },
76+
});
7777

7878
return () =>
7979
getFileUploadUrl(uuid).then((url) =>
80-
axios.post(
81-
url,
82-
{ files: file },
83-
{
84-
signal: controller.signal,
85-
headers: { 'Content-Type': 'multipart/form-data' },
86-
params: { directory },
87-
onUploadProgress: (data) => onUploadProgress(data, file.name),
88-
}
89-
)
80+
axios
81+
.post(
82+
url,
83+
{ files: file },
84+
{
85+
signal: controller.signal,
86+
headers: { 'Content-Type': 'multipart/form-data' },
87+
params: { directory },
88+
onUploadProgress: (data) => onUploadProgress(data, file.name),
89+
}
90+
)
91+
.then(() => timeouts.value.push(setTimeout(() => removeFileUpload(file.name), 500)))
9092
);
9193
});
9294

resources/scripts/state/server/files.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface ServerFileStore {
2121
setUploadProgress: Action<ServerFileStore, { name: string; loaded: number }>;
2222
clearFileUploads: Action<ServerFileStore>;
2323
removeFileUpload: Action<ServerFileStore, string>;
24+
cancelFileUpload: Action<ServerFileStore, string>;
2425
}
2526

2627
const files: ServerFileStore = {
@@ -61,6 +62,12 @@ const files: ServerFileStore = {
6162
}),
6263

6364
removeFileUpload: action((state, payload) => {
65+
if (state.uploads[payload]) {
66+
delete state.uploads[payload];
67+
}
68+
}),
69+
70+
cancelFileUpload: action((state, payload) => {
6471
if (state.uploads[payload]) {
6572
// Abort the request if it is still in flight. If it already completed this is
6673
// a no-op.

0 commit comments

Comments
 (0)