Skip to content

Commit

Permalink
Add onLoad function to onClick
Browse files Browse the repository at this point in the history
  • Loading branch information
RodriSanchez1 committed Dec 11, 2023
1 parent c3378ff commit 371c1eb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/components/UI/InputImage/InputImage.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ class InputImage extends Component {
/**
* Callback fired when loading state changes
*/
onLoad: PropTypes.func.isRequired,
onLoad: PropTypes.func.isRequired
};

async resizeImage(file, imageName = null) {
const { onLoad } = this.props;
//if you cancel the image uploaded, the event is dispached and the file is null
try {
const { onChange } = this.props;
Expand All @@ -51,9 +52,12 @@ class InputImage extends Component {
} catch (err) {
console.error(err);
}
onLoad(false);
}

onClick = async () => {
const { onLoad } = this.props;
onLoad(true);
try {
const imageURL = await window.cordova.plugins.safMediastore.selectFile();
const imageName = await window.cordova.plugins.safMediastore.getFileName(
Expand Down Expand Up @@ -90,13 +94,12 @@ class InputImage extends Component {

handleChange = async event => {
const { onLoad } = this.props;
onLoad(true)
onLoad(true);
const file = event.target.files[0];
if (file) {
//if you cancel the image uploaded, the event is dispached and the file is null
await this.resizeImage(file);
}
onLoad(false)
};
render() {
const { intl } = this.props;
Expand Down

0 comments on commit 371c1eb

Please sign in to comment.