From 29275c9c79b3ac27719f2b334b0c6d694f95ff8a Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 29 Sep 2020 19:56:00 +0200 Subject: stub episode form and index --- .../app/views/episode/containers/episode.edit.js | 52 ++++++++++++++++ .../app/views/episode/containers/episode.index.js | 71 ++++++++++++++++++++++ .../app/views/episode/containers/episode.new.js | 62 +++++++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 animism-align/frontend/app/views/episode/containers/episode.edit.js create mode 100644 animism-align/frontend/app/views/episode/containers/episode.index.js create mode 100644 animism-align/frontend/app/views/episode/containers/episode.new.js (limited to 'animism-align/frontend/app/views/episode/containers') diff --git a/animism-align/frontend/app/views/episode/containers/episode.edit.js b/animism-align/frontend/app/views/episode/containers/episode.edit.js new file mode 100644 index 0000000..4d7e270 --- /dev/null +++ b/animism-align/frontend/app/views/episode/containers/episode.edit.js @@ -0,0 +1,52 @@ +import React, { Component } from 'react' +import { connect } from 'react-redux' + +import { history } from 'app/store' +import actions from 'app/actions' + +import { Loader } from 'app/common' + +import EpisodeForm from '../components/episode.form' +import EpisodeMenu from '../components/episode.menu' + +class EpisodeEdit extends Component { + componentDidMount() { + console.log(this.props.match.params.id) + actions.episode.show(this.props.match.params.id) + } + + handleSubmit(data) { + actions.episode.update(data) + .then(response => { + // response + console.log(response) + history.push('/episode/') + }) + } + + render() { + const { show } = this.props.episode + if (show.loading || !show.res) { + return ( +
+ +
+ ) + } + return ( +
+ + +
+ ) + } +} + +const mapStateToProps = state => ({ + episode: state.episode, +}) + +export default connect(mapStateToProps)(EpisodeEdit) diff --git a/animism-align/frontend/app/views/episode/containers/episode.index.js b/animism-align/frontend/app/views/episode/containers/episode.index.js new file mode 100644 index 0000000..0cf3b6c --- /dev/null +++ b/animism-align/frontend/app/views/episode/containers/episode.index.js @@ -0,0 +1,71 @@ +import React, { Component } from 'react' +import { Link } from 'react-router-dom' +import { connect } from 'react-redux' + +import { Loader } from 'app/common' +import actions from 'app/actions' + +import EpisodeMenu from '../components/episode.menu' + +// const { result, collectionLookup } = this.props + +class EpisodeIndex extends Component { + componentDidMount() { + this.fetch() + } + + fetch() { + actions.episode.index() + } + + render() { + const { loading, lookup, order } = this.props.episode.index + if (loading) { + return ( +
+ +
+ ) + } + if (!lookup || !order.length) { + return ( +
+
+ +
+

Episodes

+

+ {"No episodes"} +

+
+
+
+ ) + } + return ( +
+
+ +
+

Episodes

+ {order.map(id => ( +
+ {'Episode '}{lookup[id].episode_number}{': '} + + lookup[id].title + +
+ ))} +
+
+ {order.length >= 50 && } +
+ ) + } +} + +const mapStateToProps = state => ({ + episode: state.episode, +}) + +export default connect(mapStateToProps)(EpisodeIndex) diff --git a/animism-align/frontend/app/views/episode/containers/episode.new.js b/animism-align/frontend/app/views/episode/containers/episode.new.js new file mode 100644 index 0000000..42e9837 --- /dev/null +++ b/animism-align/frontend/app/views/episode/containers/episode.new.js @@ -0,0 +1,62 @@ +import React, { Component } from 'react' +import { Link } from 'react-router-dom' +import { connect } from 'react-redux' + +import { history } from 'app/store' +import actions from 'app/actions' + +import EpisodeForm from '../components/episode.form' +import EpisodeMenu from '../components/episode.menu' + +class EpisodeNew extends Component { + state = { + loading: true, + initialData: {}, + } + + componentDidMount() { + this.setState({ loading: false }) + } + + handleSubmit(data) { + console.log(data) + actions.episode.create(data) + .then(res => { + console.log(res) + if (res.res && res.res.id) { + history.push('/episode/') + } + }) + .catch(err => { + console.error('error') + }) + } + + render() { + if (this.state.loading) { + return ( +
+ ) + } + return ( +
+ + +
+ ) + } +} + +const mapStateToProps = state => ({ + episode: state.episode, +}) + +const mapDispatchToProps = dispatch => ({ + // uploadActions: bindActionCreators({ ...uploadActions }, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(EpisodeNew) -- cgit v1.2.3-70-g09d2