Skip to content

Commit

Permalink
use early returns
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrammatiko authored Jul 26, 2024
1 parent 9c234b5 commit d357b4c
Showing 1 changed file with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,31 +172,34 @@ export default {
);
}

// Automatically select the last uploaded item when media manager is inside an iframe
if (window.location !== window.parent.location) {
if (state.files.length) {
const selectedFile = state.files.find((item) => item.name === file.name);
if (selectedFile) {
state.selectedItems = [selectedFile];

window.parent.document.dispatchEvent(
new CustomEvent('onMediaFileSelected', {
bubbles: true,
cancelable: false,
detail: {
type: selectedFile.type,
path: selectedFile.path,
thumb: selectedFile.thumb,
fileType: selectedFile.mime_type ? selectedFile.mime_type : false,
extension: selectedFile.extension ? selectedFile.extension : false,
width: selectedFile.width ? selectedFile.width : 0,
height: selectedFile.height ? selectedFile.height : 0,
},
}),
);
}
}
// Automatically select the last uploaded item when the media manager is inside an iframe
if (window.location === window.parent.location || !state.files.length) {
return;
}

const selectedFile = state.files.find((item) => item.name === file.name);

if (!selectedFile) {
return;
}

state.selectedItems = [selectedFile];

window.parent.document.dispatchEvent(
new CustomEvent('onMediaFileSelected', {
bubbles: true,
cancelable: false,
detail: {
type: selectedFile.type,
path: selectedFile.path,
thumb: selectedFile.thumb,
fileType: selectedFile.mime_type ? selectedFile.mime_type : false,
extension: selectedFile.extension ? selectedFile.extension : false,
width: selectedFile.width ? selectedFile.width : 0,
height: selectedFile.height ? selectedFile.height : 0,
},
}),
);
},

/**
Expand Down

0 comments on commit d357b4c

Please sign in to comment.