Skip to content

Commit f07b0de

Browse files
committed
fix removal bug
1 parent c6c05b2 commit f07b0de

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

web_src/js/features/repo-legacy.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ async function onEditContent(event) {
284284
if ($dropzone.length === 1) {
285285
$dropzone.data('saved', false);
286286

287-
const fileUuidDict = {}; // if a comment has been saved, then the uploaded files won't be deleted when clicking the Remove in the dropzone
287+
let disableRemovedfileEvent = false; // when resetting the dropzone (removeAllFiles), disable the removedfile event
288+
let fileUuidDict = {}; // if a comment has been saved, then the uploaded files won't be deleted from server when clicking the Remove in the dropzone
288289
dz = await createDropzone($dropzone[0], {
289290
url: $dropzone.data('upload-url'),
290291
headers: {'X-Csrf-Token': csrfToken},
@@ -308,6 +309,7 @@ async function onEditContent(event) {
308309
$dropzone.find('.files').append(input);
309310
});
310311
this.on('removedfile', (file) => {
312+
if (disableRemovedfileEvent) return;
311313
$(`#${file.uuid}`).remove();
312314
if ($dropzone.data('remove-url') && !fileUuidDict[file.uuid]?.submitted) {
313315
$.post($dropzone.data('remove-url'), {
@@ -328,8 +330,11 @@ async function onEditContent(event) {
328330
});
329331
this.on('reload', () => {
330332
$.getJSON($editContentZone.data('attachment-url'), (data) => {
333+
disableRemovedfileEvent = true;
331334
dz.removeAllFiles(true);
335+
disableRemovedfileEvent = false;
332336
$dropzone.find('.files').empty();
337+
fileUuidDict = {};
333338
$.each(data, function () {
334339
const imgSrc = `${$dropzone.data('link-url')}/${this.uuid}`;
335340
dz.emit('addedfile', this);

0 commit comments

Comments
 (0)