From bbcf48825bec60dab7a4de955bc4831eadb37792 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Wed, 8 Jul 2020 15:01:29 +0200 Subject: media form and anuvva migration --- .../frontend/views/media/containers/media.edit.js | 57 +++++++++++ .../frontend/views/media/containers/media.index.js | 109 +++++++++++++++++++++ .../frontend/views/media/containers/media.new.js | 48 +++++++++ 3 files changed, 214 insertions(+) create mode 100644 animism-align/frontend/views/media/containers/media.edit.js create mode 100644 animism-align/frontend/views/media/containers/media.index.js create mode 100644 animism-align/frontend/views/media/containers/media.new.js (limited to 'animism-align/frontend/views/media/containers') diff --git a/animism-align/frontend/views/media/containers/media.edit.js b/animism-align/frontend/views/media/containers/media.edit.js new file mode 100644 index 0000000..8c353d9 --- /dev/null +++ b/animism-align/frontend/views/media/containers/media.edit.js @@ -0,0 +1,57 @@ +import React, { Component } from 'react' +import { Link } from 'react-router-dom' +import { connect } from 'react-redux' + +import { history } from '../../../store' +import actions from '../../../actions' + +import { Loader } from '../../../common' + +import MediaForm from '../components/media.form' +import MediaMenu from '../components/media.menu' + +class MediaEdit extends Component { + componentDidMount() { + console.log(this.props.match.params.id) + actions.media.show(this.props.match.params.id) + } + + handleSubmit(data) { + actions.media.update(data) + .then(response => { + // response + console.log(response) + history.push('/media/') + }) + } + + render() { + const { show } = this.props.media + if (show.loading || !show.res) { + return ( +
+ +
+ ) + } + return ( +
+ + +
+ ) + } +} + +const mapStateToProps = state => ({ + media: state.media, +}) + +const mapDispatchToProps = dispatch => ({ + // searchActions: bindActionCreators({ ...searchActions }, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(MediaEdit) diff --git a/animism-align/frontend/views/media/containers/media.index.js b/animism-align/frontend/views/media/containers/media.index.js new file mode 100644 index 0000000..09ef6ca --- /dev/null +++ b/animism-align/frontend/views/media/containers/media.index.js @@ -0,0 +1,109 @@ +import React, { Component } from 'react' +import { Link } from 'react-router-dom' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' + +import { formatDateTime } from '../../../util' +import { MenuButton, SmallMenuButton, Loader } from '../../../common' +import actions from '../../../actions' + +import MediaIndexOptions from '../components/media.indexOptions' +import MediaMenu from '../components/media.menu' + +// const { result, collectionLookup } = this.props + +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} +
+
+
+ ) +} + +const mapStateToProps = state => ({ + media: state.media, +}) + +const mapDispatchToProps = dispatch => ({ + // uploadActions: bindActionCreators({ ...uploadActions }, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(MediaIndex) diff --git a/animism-align/frontend/views/media/containers/media.new.js b/animism-align/frontend/views/media/containers/media.new.js new file mode 100644 index 0000000..88bf467 --- /dev/null +++ b/animism-align/frontend/views/media/containers/media.new.js @@ -0,0 +1,48 @@ +import React, { Component } from 'react' +import { Link } from 'react-router-dom' +import { connect } from 'react-redux' + +import { history } from '../../../store' +import actions from '../../../actions' + +import MediaForm from '../components/media.form' +import MediaMenu from '../components/media.menu' + +class MediaNew extends Component { + handleSubmit(data) { + console.log(data) + actions.media.create(data) + .then(res => { + console.log(res) + if (res.res && res.res.id) { + history.push('/media/') + } + }) + .catch(err => { + console.error('error') + }) + } + + render() { + return ( +
+ + +
+ ) + } +} + +const mapStateToProps = state => ({ + media: state.media, +}) + +const mapDispatchToProps = dispatch => ({ + // searchActions: bindActionCreators({ ...searchActions }, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(MediaNew) -- cgit v1.2.3-70-g09d2