Skip to content

Commit

Permalink
Small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
RodriSanchez1 committed Dec 11, 2023
1 parent b87121f commit 30e5ef7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/components/Board/TileEditor/TileEditor.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ export class TileEditor extends Component {
<div className="TileEditor__input-image">
<InputImage
onChange={this.handleInputImageChange}
setIsImageLoading={this.handleLoadingStateChange}
setIsLoadingImage={this.handleLoadingStateChange}
/>
</div>
</div>
Expand Down
14 changes: 7 additions & 7 deletions src/components/UI/InputImage/InputImage.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ class InputImage extends Component {
/**
* Set image loading state
*/
setIsImageLoading: PropTypes.func.isRequired
setIsLoadingImage: PropTypes.func.isRequired
};

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

onClick = async () => {
const { setIsImageLoading } = this.props;
setIsImageLoading(true);
const { setIsLoadingImage } = this.props;
try {
const imageURL = await window.cordova.plugins.safMediastore.selectFile();
const imageName = await window.cordova.plugins.safMediastore.getFileName(
imageURL
);
setIsLoadingImage(true);
const file = await new Promise((resolve, reject) => {
window.resolveLocalFileSystemURL(
imageURL,
Expand Down Expand Up @@ -90,16 +88,18 @@ class InputImage extends Component {
} catch (err) {
console.error(err);
}
setIsLoadingImage(false);
};

handleChange = async event => {
const { setIsImageLoading } = this.props;
setIsImageLoading(true);
const { setIsLoadingImage } = this.props;
setIsLoadingImage(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);
}
setIsLoadingImage(false);
};
render() {
const { intl } = this.props;
Expand Down
8 changes: 4 additions & 4 deletions src/components/UI/InputImage/InputImage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ jest.mock('./InputImage.messages', () => {
describe('InputImage tests', () => {
test('default render ', () => {
const onChange = jest.fn();
const setIsImageLoading = jest.fn();
const setIsLoadingImage = jest.fn();
const wrapper = mount(
<InputImage
disabled={false}
onChange={onChange}
setIsImageLoading={setIsImageLoading}
setIsLoadingImage={setIsLoadingImage}
/>
);
expect(wrapper).toMatchSnapshot();
});
test('on buttton click', () => {
const onChange = jest.fn();
const setIsImageLoading = jest.fn();
const setIsLoadingImage = jest.fn();
const event = {
target: {
files: [new File(['foo'], 'foo.txt')]
Expand All @@ -40,7 +40,7 @@ describe('InputImage tests', () => {
user={{ email: 'test' }}
disabled={false}
onChange={onChange}
setIsImageLoading={setIsImageLoading}
setIsLoadingImage={setIsLoadingImage}
/>
);
wrapper.find('input').prop('onChange')(event);
Expand Down

0 comments on commit 30e5ef7

Please sign in to comment.