summaryrefslogtreecommitdiff
path: root/frontend/app/views/upload/components/upload.index.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/app/views/upload/components/upload.index.js')
-rw-r--r--frontend/app/views/upload/components/upload.index.js104
1 files changed, 104 insertions, 0 deletions
diff --git a/frontend/app/views/upload/components/upload.index.js b/frontend/app/views/upload/components/upload.index.js
new file mode 100644
index 0000000..00cedc2
--- /dev/null
+++ b/frontend/app/views/upload/components/upload.index.js
@@ -0,0 +1,104 @@
+import React, { Component } from 'react'
+import { Link } from 'react-router-dom'
+
+import { uploadUri, formatDateTime } from 'app/utils'
+import { SmallMenuButton, Loader } from 'app/common'
+import actions from 'app/actions'
+
+import UploadIndexOptions from './upload.indexOptions'
+import UploadMenu from './upload.menu'
+
+// const { result, collectionLookup } = this.props
+
+export default class UploadIndex extends Component {
+ componentDidMount() {
+ this.fetch(false)
+ }
+
+ componentDidUpdate(prevProps) {
+ if (this.props.upload.options.sort !== prevProps.upload.options.sort) {
+ this.fetch(false)
+ }
+ }
+
+ fetch(load_more) {
+ const { options, index } = this.props.upload
+ const { order: index_order } = index
+ const [ sort, order ] = options.sort.split('-')
+ actions.upload.index({
+ sort, order, limit: 50, offset: load_more ? index_order.length : 0,
+ }, load_more)
+ }
+
+ render() {
+ const { searchOptions, uploadActions } = this.props
+ const { options } = this.props.upload
+ const { loading, lookup, order } = this.props.upload.index
+ if (loading) {
+ return (
+ <section>
+ <UploadIndexOptions />
+ <div className="row">
+ {order && !!order.length &&
+ <div className={'results ' + searchOptions.thumbnailSize}>
+ {order.map(id => <UploadItem key={id} data={lookup[id]} />)}
+ </div>
+ }
+ </div>
+ <Loader />
+ </section>
+ )
+ }
+ if (!lookup || !order.length) {
+ return (
+ <section>
+ <UploadIndexOptions />
+ <div className="row">
+ <UploadMenu uploadActions={uploadActions} />
+ <p className='gray'>
+ {"No uploads"}
+ </p>
+ </div>
+ </section>
+ )
+ }
+ return (
+ <section>
+ <UploadIndexOptions />
+ <div className="row">
+ <UploadMenu uploadActions={uploadActions} />
+ <div className={'results ' + searchOptions.thumbnailSize}>
+ {order.map(id => <UploadItem key={id} data={lookup[id]} />)}
+ </div>
+ </div>
+ {order.length >= 50 && <button className='loadMore' onClick={() => this.fetch(true)}>Load More</button>}
+ </section>
+ )
+ }
+}
+
+const UploadItem = ({ data }) => {
+ // console.log(data)
+ const imageUri = uploadUri(data)
+ return (
+ <div className='cell'>
+ <div className='img'>
+ <Link to={"/upload/" + data.id + "/show/"}>
+ <img src={imageUri} alt={"Uploaded image"} />
+ </Link>
+ </div>
+ <div className='meta center'>
+ <div className='row'>
+ <SmallMenuButton name="search" href={"/search/upload/" + data.id + "/"} />
+ </div>
+ <div>
+ {data.username}
+ </div>
+ <div>
+ {formatDateTime(data.created_at)}
+ </div>
+ </div>
+ </div>
+ )
+}
+