summaryrefslogtreecommitdiff
path: root/animism-align/frontend/views
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2020-07-08 11:17:43 +0200
committerJules Laplace <julescarbon@gmail.com>2020-07-08 11:17:43 +0200
commit084d11a05fe1220c5104ea59f4fab4860e70b434 (patch)
tree4dc451af37dba93d9449036563517d39af4e6ccb /animism-align/frontend/views
parenta9ed0ec5486a6bd63f706592dd1eaa01f6c2ea1d (diff)
stubbing media index
Diffstat (limited to 'animism-align/frontend/views')
-rw-r--r--animism-align/frontend/views/media/components/media.index.js98
-rw-r--r--animism-align/frontend/views/media/media.container.js37
-rw-r--r--animism-align/frontend/views/media/media.css1
-rw-r--r--animism-align/frontend/views/media/media.reducer.js22
4 files changed, 158 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>
+ )
+}
+
diff --git a/animism-align/frontend/views/media/media.container.js b/animism-align/frontend/views/media/media.container.js
new file mode 100644
index 0000000..280efd0
--- /dev/null
+++ b/animism-align/frontend/views/media/media.container.js
@@ -0,0 +1,37 @@
+import React, { Component } from 'react'
+import { Route, Link } from 'react-router-dom'
+import { bindActionCreators } from 'redux'
+import { connect } from 'react-redux'
+
+import './media.css'
+
+import actions from '../../actions'
+
+import MediaIndex from './components/media.index'
+// import MediaShow from './components/media.show'
+// import MediaNew from './components/media.new'
+// import MediaEdit from './components/media.edit'
+
+class Container extends Component {
+ render() {
+ return (
+ <div className='media'>
+ <Route exact path='/media/' component={MediaIndex} />
+ </div>
+ )
+ }
+}
+/*
+ <Route exact path='/media/:id/edit/' component={MediaEdit} />
+ <Route exact path='/media/new/' component={MediaNew} />
+ <Route exact path='/media/:id/show/' component={MediaShow} />
+*/
+const mapStateToProps = state => ({
+ media: state.media,
+})
+
+const mapDispatchToProps = dispatch => ({
+ // uploadActions: bindActionCreators({ ...uploadActions }, dispatch),
+})
+
+export default connect(mapStateToProps, mapDispatchToProps)(Container)
diff --git a/animism-align/frontend/views/media/media.css b/animism-align/frontend/views/media/media.css
new file mode 100644
index 0000000..56cf2fe
--- /dev/null
+++ b/animism-align/frontend/views/media/media.css
@@ -0,0 +1 @@
+* {} \ No newline at end of file
diff --git a/animism-align/frontend/views/media/media.reducer.js b/animism-align/frontend/views/media/media.reducer.js
new file mode 100644
index 0000000..bc885e8
--- /dev/null
+++ b/animism-align/frontend/views/media/media.reducer.js
@@ -0,0 +1,22 @@
+import * as types from '../../types'
+import { session, getDefault, getDefaultInt } from '../../session'
+
+import { crudState, crudReducer } from '../../api/crud.reducer'
+
+const initialState = crudState('media', {
+ options: {
+ sort: getDefault('media.sort', 'id-desc'),
+ thumbnailSize: getDefault('upload.thumbnailSize', 'small'),
+ }
+})
+
+const reducer = crudReducer('media')
+
+export default function mediaReducer(state = initialState, action) {
+ // console.log(action.type, action)
+ state = reducer(state, action)
+ switch (action.type) {
+ default:
+ return state
+ }
+}