From 084d11a05fe1220c5104ea59f4fab4860e70b434 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 8 Jul 2020 11:17:43 +0200 Subject: stubbing media index --- animism-align/frontend/types.js | 1 + .../frontend/views/media/components/media.index.js | 98 ++++++++++++++++++++++ .../frontend/views/media/media.container.js | 37 ++++++++ animism-align/frontend/views/media/media.css | 1 + .../frontend/views/media/media.reducer.js | 22 +++++ 5 files changed, 159 insertions(+) create mode 100644 animism-align/frontend/views/media/components/media.index.js create mode 100644 animism-align/frontend/views/media/media.container.js create mode 100644 animism-align/frontend/views/media/media.css create mode 100644 animism-align/frontend/views/media/media.reducer.js (limited to 'animism-align/frontend') 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 ( +
+ +
+ {order && !!order.length && +
+ {order.map(id => )} +
+ } +
+ +
+ ) + } + if (!lookup || !order.length) { + return ( +
+ +
+ +

+ {"No media"} +

+
+
+ ) + } + return ( +
+ +
+ +
+ {order.map(id => )} +
+
+ {order.length >= 50 && } +
+ ) + } +} + +const MediaItem = ({ data }) => { + // console.log(data) + return ( +
+
+ + {data.title} + +
+
+
+ {data.title}
+ {data.author} +
+
+
+ ) +} + 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 ( +
+ +
+ ) + } +} +/* + + + +*/ +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 + } +} -- cgit v1.2.3-70-g09d2