Skip to content

Commit

Permalink
Merge pull request #562 from battlecode/avatar-and-resume-size-check
Browse files Browse the repository at this point in the history
frontend avatar and resume file size check
  • Loading branch information
maggiehuiliyao authored Jan 25, 2023
2 parents 3ac9ee7 + e1cadce commit ab69f10
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions frontend/src/components/avatarUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class AvatarUpload extends Component {
} else {
this.setState({ status: "failure" });
}
setTimeout(() => {
this.setState({ status: "waiting" });
}, 2000);
});
setTimeout(() => {
this.setState({ status: "waiting" });
}, 2000);
}

render() {
Expand Down
19 changes: 19 additions & 0 deletions frontend/src/views/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ class Account extends Component {
}

uploadResume = () => {
const fileSize = this.state.selectedResumeFile.size / 1024 / 1024; // in MiB
if (fileSize > 5) {
let alert_message =
"Ensure this file size is not greater than 5 MiB. Your current file size is " +
Number(fileSize.toPrecision(3)) +
" MiB.";
this.setState({ alert_message: alert_message });
this.setState({ resume_status: "waiting" });
return;
}
this.setState({ resume_status: "loading" });
Api.resumeUpload(this.state.selectedResumeFile, (success) => {
if (success) {
Expand All @@ -117,6 +127,15 @@ class Account extends Component {
};

uploadAvatar = (selected_file, callback) => {
const fileSize = selected_file.size / 1024 / 1024; // in MiB
if (fileSize > 5) {
let alert_message =
"Ensure this file size is not greater than 5 MiB. Your current file size is " +
Number(fileSize.toPrecision(3)) +
" MiB.";
this.setState({ alert_message: alert_message });
return;
}
Api.avatarUpload(selected_file, (response, success) => {
if (success) {
this.props.updateBaseState();
Expand Down

0 comments on commit ab69f10

Please sign in to comment.