feat: clear existing files and previews when adding a file to a single-limit MediaDropzone
This commit is contained in:
parent
cce733e288
commit
4afba34a57
@ -63,6 +63,23 @@ function formatBytes(bytes: number): string {
|
||||
}
|
||||
|
||||
function onAddedFile(item: { id: string; file: File }) {
|
||||
if (props.maxFiles === 1) {
|
||||
state.value.existing.forEach((existingItem) => {
|
||||
if (!state.value.removeIds.includes(existingItem.id)) {
|
||||
state.value.removeIds.push(existingItem.id);
|
||||
}
|
||||
});
|
||||
state.value.existing = [];
|
||||
|
||||
const previewsCopy = [...filePreviews.value];
|
||||
previewsCopy.forEach((p) => {
|
||||
dropzoneRef.value?.removeFile(p.id);
|
||||
});
|
||||
filePreviews.value.forEach((p) => URL.revokeObjectURL(p.objectUrl));
|
||||
filePreviews.value = [];
|
||||
state.value.newFiles = [];
|
||||
}
|
||||
|
||||
state.value.newFiles.push(item.file);
|
||||
filePreviews.value.push({
|
||||
id: item.id,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user