Skip to content

Commit

Permalink
add loader place holder for pre-fetched images
Browse files Browse the repository at this point in the history
  • Loading branch information
nasser85 committed Jul 17, 2018
1 parent 515d171 commit 6406d73
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
Binary file added src/assets/loader.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions src/components/GoogleMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export default class GoogleMap extends Component {
mapPins: [],
imageViewer: false,
imagesForViewer: [],
imageCache: {},
loader: false
imageCache: {}
}
this.createGenericMap = this.createGenericMap.bind(this)
this.goToPlace = this.goToPlace.bind(this)
Expand Down Expand Up @@ -121,7 +120,8 @@ export default class GoogleMap extends Component {
}
viewNASAImage(location, lat, lng, markerObj) {
this.setState({
loader: true
imageViewer: true,

})

EarthFactory.fetchImage(lat, lng)
Expand Down Expand Up @@ -155,7 +155,6 @@ export default class GoogleMap extends Component {
imageCache[location] = imagesForViewer[0][0]
}
this.setState({
loader: false,
imageViewer: true,
imagesForViewer,
imageCache
Expand Down
35 changes: 29 additions & 6 deletions src/components/ImageViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react'
import Close from 'react-icons/lib/md/clear'
import Right from 'react-icons/lib/md/keyboard-arrow-right'
import Left from 'react-icons/lib/md/keyboard-arrow-left'
import Loader from '../assets/loader.gif'

import '../styles/ImageViewer.css'

Expand All @@ -13,27 +14,49 @@ export default class ImageViewer extends Component {
}
this.closeViewer = this.closeViewer.bind(this)
this.logError = this.logError.bind(this)
this.onImageLoad = this.onImageLoad.bind(this)
this.renderMainImage = this.renderMainImage.bind(this)
this.renderCaption = this.renderCaption.bind(this)
}
closeViewer() {
this.props.close()
}
logError() {
this.props.onBroken(this.props.images[this.state.index][1], this.props.images[this.state.index][2])
}
render() {
console.log(this.props.images)
onImageLoad() {
document.getElementById('place-image').classList.remove('hidden')
document.getElementById('loader').classList.add('hidden')
}
renderCaption() {
let leftClass = this.state.index > 0 ? "image-left-arrow color-white"
: "image-left-arrow color-white hidden"
let rightClass = this.state.index < this.props.images.length-1 ? "image-right-arrow color-white"
: "image-right-arrow color-white hidden"
return (
<div className="main-image-caption">
<Left className={leftClass} /><p className="main-image-text color-white">{this.props.images.length ? this.props.images[this.state.index][1] : ' '}</p><Right className={rightClass} />
</div>
)
}
renderMainImage() {
return (
<img id="place-image"
alt={this.props.images[this.state.index][1]}
className="main-image hidden"
src={this.props.images[this.state.index][0]}
onError={this.logError}
onLoad={this.onImageLoad}></img>
)
}
render() {
return (
<div className="image-viewer">
<Close onClick={this.closeViewer} className="close-button color-white" />
<div className="main-image-container">
<img id="place-image" alt={this.props.images[this.state.index][1]} className="main-image" src={this.props.images[this.state.index][0]} onError={this.logError}/>
<div className="main-image-caption">
<Left className={leftClass} /><p className="main-image-text color-white">{this.props.images[this.state.index][1]}</p><Right className={rightClass} />
</div>
{ this.props.images.length ? this.renderMainImage() : false }
<img id="loader" className="main-image" src={Loader} />
{ this.renderCaption() }
</div>
</div>
)
Expand Down
4 changes: 4 additions & 0 deletions src/styles/ImageViewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
}
.main-image-caption {
padding: 0px 5px;
min-height: 70px;
}
.main-image-text {
text-align: center;
Expand All @@ -56,4 +57,7 @@
}
.image-left-arrow.hidden, .image-right-arrow.hidden {
display: none;
}
.main-image.hidden {
display: none;
}

0 comments on commit 6406d73

Please sign in to comment.