Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add max upload size to image uploader #293

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

PraggyaJ
Copy link
Contributor

@PraggyaJ PraggyaJ commented Mar 1, 2018

screen shot 2018-03-01 at 8 26 10 pm

The image uploader only accepts images with a size less than 300 KB and alerts the user which files were too big.

Copy link
Member

@emilgoldsmith emilgoldsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! I notice some good attention to detail here, really appreciate that @PraggyaJ !

Just a few small comments, and then as you can see you've accidentally made the whole admin components directory executable it seems haha, so just undo that ;).

static/admin.css Outdated
@@ -3,6 +3,10 @@
color: black;
}

body{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this an accident?

@@ -138,6 +148,14 @@ export default class ImageUploader extends BaseComponent {
this.addImagePreviewUrl(file);
});

if (tooLargeFileNames.length !== 0) {
let names = '\n';
tooLargeFileNames.forEach((file) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, good job! But there's a smoother way we can do it, like this:

const alertMessage = tooLargeFileNames.reduce((currentMessage, filename) => {
  return `${currentMessage}\n${file.name} (${sizeCalculation) KB)`;
}, 'The following files exceeded the maximum upload size:\n');

See these docs for an explanation of the reduce function

tooLargeFileNames.forEach((file) => {
names = names.concat(` ${file.name} (${(file.size / 1024).toFixed(2)} KB)\n`);
});
alert(`The following exceeded the maximum upload size: ${names}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just make this the following files... (adding in "files").

Also, it would generally be a lot more natural to add the newline in here instead of as the first part of the string above, so just making it size:\n${names}), but with my above approach you can do it all in one and just do alert(alertMessage) here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of alert, let's use a Material UI dialog box. This falls in line with the rest of the Admin Interface and is just a little less jarring than an alert message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you're right, let's keep things pretty! I'll try not to fall into my old habits ;)

tooLargeFileNames.forEach((file) => {
names = names.concat(` ${file.name} (${(file.size / 1024).toFixed(2)} KB)\n`);
});
alert(`The following exceeded the maximum upload size: ${names}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of alert, let's use a Material UI dialog box. This falls in line with the rest of the Admin Interface and is just a little less jarring than an alert message.

});
alert(`The following exceeded the maximum upload size: ${names}`);
}

// Reset to "No Files Chosen" in the input element instead of saying "10 files" or so
e.target.parentNode.parentNode.parentNode.parentNode.parentNode.reset();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be a more elegant way to do this. What are all the .parentNodes referring to here??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, it was just really hard getting a ref to it or something like that, it is without a doubt ugly though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants