Skip to content

Commit

Permalink
selectedImages now set via props change
Browse files Browse the repository at this point in the history
  • Loading branch information
benhowell committed Sep 3, 2016
1 parent 055db68 commit 89ef8fd
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions src/Gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import React, { Component, PropTypes } from 'react';
import Lightbox from 'react-images';
import Image from './Image.js';

var update = require('react-addons-update');

class Gallery extends Component {
constructor (props) {
super(props);
Expand Down Expand Up @@ -45,13 +43,6 @@ class Gallery extends Component {
}
}

componentWillUpdate (np, ns) {
if(np.selectedImages != ns.selectedImages){
if(this.props.onSelectedImagesChange)
this.props.onSelectedImagesChange(ns.selectedImages);
}
}

componentDidUpdate () {
if (!this._gallery) return;
if (this._gallery.clientWidth
Expand Down Expand Up @@ -104,17 +95,14 @@ class Gallery extends Component {
onToggleSelected (index, event) {
event.preventDefault();
var i = this.state.selectedImages.indexOf(index);
if(i == -1){
this.setState({selectedImages:
update(this.state.selectedImages,
{$push: [index]})});
}
else {
this.setState({
selectedImages: update(this.state.selectedImages,
{$splice: [[i, 1]]})
});
}
var selectedImages = this.state.selectedImages.slice();
if(i == -1)
selectedImages.push(index);
else
selectedImages.splice(i,1);

if(this.props.onSelectedImagesChange)
this.props.onSelectedImagesChange(selectedImages);
}

getOnClickThumbnailFunc () {
Expand Down Expand Up @@ -176,7 +164,8 @@ class Gallery extends Component {
return row;
}

scaleThumb (item) {

setThumbScale (item) {
item.scaletwidth =
Math.floor(this.props.rowHeight
* (item.thumbnailWidth / item.thumbnailHeight));
Expand All @@ -189,7 +178,7 @@ class Gallery extends Component {

var items = this.state.images.slice();
for (var t in items) {
this.scaleThumb(items[t]);
this.setThumbScale(items[t]);
}

var images = [];
Expand All @@ -207,8 +196,6 @@ class Gallery extends Component {
}

render () {
console.log("render");

var images = this.state.thumbnails.map((item, idx) => {
return <Image
key={"Image-"+idx}
Expand Down

0 comments on commit 89ef8fd

Please sign in to comment.