diff options
Diffstat (limited to 'animism-align/frontend/views/media/components/media.index.js')
| -rw-r--r-- | animism-align/frontend/views/media/components/media.index.js | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/animism-align/frontend/views/media/components/media.index.js b/animism-align/frontend/views/media/components/media.index.js new file mode 100644 index 0000000..a4127f9 --- /dev/null +++ b/animism-align/frontend/views/media/components/media.index.js @@ -0,0 +1,98 @@ +import React, { Component } from 'react' +import { Link } from 'react-router-dom' + +import { formatDateTime } from '../../../util' +import { MenuButton, SmallMenuButton, Loader } from '../../../common' +import actions from '../../../actions' + +import MediaIndexOptions from './media.indexOptions' +import MediaMenu from './media.menu' + +// const { result, collectionLookup } = this.props + +export default class MediaIndex extends Component { + componentDidMount() { + this.fetch(false) + } + + componentDidUpdate(prevProps) { + if (this.props.media.options.sort !== prevProps.media.options.sort) { + this.fetch(false) + } + } + + fetch(load_more) { + const { options, index } = this.props.media + const { order: index_order } = index + const [ sort, order ] = options.sort.split('-') + actions.media.index({ + sort, order, limit: 5000, // offset: load_more ? index_order.length : 0, + }, load_more) + } + + render() { + const { mediaActions } = this.props + const { options } = this.props.media + const { loading, lookup, order } = this.props.media.index + if (loading) { + return ( + <section> + <MediaIndexOptions /> + <div className="row"> + {order && !!order.length && + <div className={'results ' + options.thumbnailSize}> + {order.map(id => <MediaItem key={id} data={lookup[id]} />)} + </div> + } + </div> + <Loader /> + </section> + ) + } + if (!lookup || !order.length) { + return ( + <section> + <MediaIndexOptions /> + <div className="row"> + <MediaMenu /> + <p className='gray'> + {"No media"} + </p> + </div> + </section> + ) + } + return ( + <section> + <MediaIndexOptions /> + <div className="row"> + <MediaMenu /> + <div className={'results ' + options.thumbnailSize}> + {order.map(id => <MediaItem key={id} data={lookup[id]} />)} + </div> + </div> + {order.length >= 50 && <button className='loadMore' onClick={() => this.fetch(true)}>Load More</button>} + </section> + ) + } +} + +const MediaItem = ({ data }) => { + // console.log(data) + return ( + <div className='cell'> + <div className='img'> + <Link to={"/media/" + data.id + "/show/"}> + <img src={data.thumb_url} alt={data.title} /> + </Link> + </div> + <div className='meta center'> + <div> + {data.title}<br /> + {data.author} + </div> + </div> + </div> + ) +} + |
