Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
#935 Loader for image widget
Browse files Browse the repository at this point in the history
  • Loading branch information
damianprzygodzki committed Jun 26, 2017
1 parent 086754b commit 13b9ca3
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions src/components/widget/Image.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import React, { Component } from 'react';
import { getImageAction, postImageAction } from '../../actions/AppActions';
import Loader from '../app/Loader';

const Placeholder = (props) => (
<div className="image-placeholder">
<div
className="placeholder-value"
>
{props.children}
</div>
</div>
);

class Image extends Component{
constructor(props){
Expand Down Expand Up @@ -185,6 +196,26 @@ class Image extends Component{
Take from camera
</div>
}

renderImagePreview() {
const {isLoading, imageSrc} = this.state;
const {fields} = this.props;

if(isLoading)
return <Placeholder><Loader /></Placeholder>
else if(imageSrc)
return (
<div className="image-preview">
<img
src={imageSrc}
alt="image"
className="img-fluid"
/>
</div>
);
else
return <Placeholder>{fields[0].emptyText}</Placeholder>
}

render(){
const { imageSrc, usingCamera } = this.state;
Expand All @@ -196,21 +227,7 @@ class Image extends Component{
onKeyDown={this.handleKeyDown}
tabIndex={0}
>
{imageSrc ?
<div className="image-preview">
<img
src={imageSrc}
alt="image"
className="img-fluid"
/>
</div>
:
<div className="image-placeholder">
<div
className="placeholder-value"
>{fields[0].emptyText}</div>
</div>
}
{this.renderImagePreview()}

{usingCamera && this.renderVideoPreview()}

Expand Down

0 comments on commit 13b9ca3

Please sign in to comment.