import React from 'react'
import cookie from 'react-cookie'
import Header from './Header'
import NavBar from './NavBar'
import Gallery from './Gallery'
import GalleryPhoto from './GalleryPhoto'
import Sort from './Sort'

// database functions
import getRequest from '../getRequest.js'
import postRequest from '../postRequest.js'

// material-ui helpers
import GetMuiTheme from 'material-ui/lib/styles/getMuiTheme'
import MyTheme from '../theme.js'
import injectTapEventPlugin from 'react-tap-event-plugin'
injectTapEventPlugin();

export default React.createClass({
  childContextTypes : {
    muiTheme: React.PropTypes.object
  },

  getChildContext() {
    return {
      muiTheme: GetMuiTheme(MyTheme),
    };
  },

    getInitialState: function () {
    return {
      amountDonated: 0,
      gallery: []
    }
  },

  componentDidMount: function() {
    // get all the recipients from the database
    getRequest('http://localhost:3000/recipients', this.dbSetState)
  //  session.user.id = "testuserid"
  },

  dbSetState: function (err, data) {
    this.setState({gallery: data})
  },

  sortHandleChange: function(event, index, value) {
    this.setState({valueSort:sortName})
  },

  setGalleryState: function (newGallery) {
    this.setState({gallery: newGallery})
  },

  // setgallery state function takes in a gallery and sets the state to equal new gallery passed in

  render () {
    console.log("DONOR ID COOKIE: ", cookie.load('donorID'))
    
    return (
      <div className='app'>
        <NavBar/>
        <Header header='TOOTH & PAIL'/>
        <Sort gallery={this.state.gallery} setGalleryState={this.setGalleryState}/>
        <Gallery gallery={this.state.gallery}/>

      </div>
    )
  }
})

@@ -1086,16 +1086,19 @@
 %0A  %7D,%0A%0A 
+ //
  sortHan
@@ -1137,24 +1137,27 @@
 , value) %7B%0A 
+ //
    this.setS
@@ -1185,21 +1185,31 @@
 ame%7D)%0A  
-%7D,%0A%0A 
+// %7D,%0A  //%0A  //
  setGall
@@ -1239,24 +1239,27 @@
 Gallery) %7B%0A 
+ //
    this.setS
@@ -1283,24 +1283,27 @@
 wGallery%7D)%0A 
+ //
  %7D,%0A%0A  // se
@@ -1475,13 +1475,9 @@
 '))%0A
-    
 %0A
+
     
@@ -1575,92 +1575,8 @@
 '/%3E%0A
-        %3CSort gallery=%7Bthis.state.gallery%7D setGalleryState=%7Bthis.setGalleryState%7D/%3E%0A
     
@@ -1619,17 +1619,16 @@
 lery%7D/%3E%0A
-%0A
       %3C/

Fix broken gallery