summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/venue/containers/venue.index.js
blob: 9ab9ba15a94ae3bb30c8d55812f9f65359c7b7d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React, { Component } from 'react'
import { Link } from 'react-router-dom'
import { connect } from 'react-redux'

import { Loader } from 'app/common'
import actions from 'app/actions'

import VenueMenu from '../components/venue.menu'

// const { result, collectionLookup } = this.props

class VenueIndex extends Component {
  componentDidMount() {
    this.fetch()
  }

  fetch() {
    actions.venue.index()
  }

  render() {
    const { loading, lookup, order } = this.props.venue.index
    const project_id = parseInt(this.props.match.params.id)
    if (loading || this.props.project.loading) {
      return (
        <section>
          <Loader />
        </section>
      )
    }
    if (!lookup || !order.length) {
      return (
        <section>
          <div className="row venue-index">
            <VenueMenu />
            <div>
              <h1>Venues</h1>
              <p className='gray'>
                {"No venues"}
              </p>
            </div>
          </div>
        </section>
      )
    }
    const project = this.props.project.lookup[project_id]
    return (
      <section>
        <div className="row venue-index">
          <VenueMenu />
          <div className="venue-list">
            <h1>{project.title}</h1>
            <h2>Venues</h2>
            {order.map(id => (
              lookup[id].project_id === project_id && (
                <div key={id}>
                  <Link to={"/venue/" + id + "/edit/"}>
                    {lookup[id].title}
                  </Link>
                  {lookup[id].date}
                </div>
              )
            ))}
          </div>
        </div>
        {order.length >= 50 && <button className='loadMore' onClick={() => this.fetch(true)}>Load More</button>}
      </section>
    )
  }
}

const mapStateToProps = state => ({
  project: state.project.index,
  venue: state.venue,
})

export default connect(mapStateToProps)(VenueIndex)