diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-07-08 11:17:43 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-07-08 11:17:43 +0200 |
| commit | 084d11a05fe1220c5104ea59f4fab4860e70b434 (patch) | |
| tree | 4dc451af37dba93d9449036563517d39af4e6ccb | |
| parent | a9ed0ec5486a6bd63f706592dd1eaa01f6c2ea1d (diff) | |
stubbing media index
| -rw-r--r-- | animism-align/frontend/types.js | 1 | ||||
| -rw-r--r-- | animism-align/frontend/views/media/components/media.index.js | 98 | ||||
| -rw-r--r-- | animism-align/frontend/views/media/media.container.js | 37 | ||||
| -rw-r--r-- | animism-align/frontend/views/media/media.css | 1 | ||||
| -rw-r--r-- | animism-align/frontend/views/media/media.reducer.js | 22 |
5 files changed, 159 insertions, 0 deletions
diff --git a/animism-align/frontend/types.js b/animism-align/frontend/types.js index 45c9caf..f92f70b 100644 --- a/animism-align/frontend/types.js +++ b/animism-align/frontend/types.js @@ -3,6 +3,7 @@ import { with_type, crud_type } from './api/crud.types' export const api = crud_type('api', []) export const upload = crud_type('upload', []) +export const media = crud_type('media', []) export const peaks = crud_type('peaks', []) export const text = crud_type('text', []) export const annotation = crud_type('annotation', []) 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 + } +} |
