summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/episode/containers
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2021-03-09 17:50:09 +0100
committerJules Laplace <julescarbon@gmail.com>2021-03-09 17:50:09 +0100
commit786404a8a692448b04fd8df5dbca8013631a0abd (patch)
tree3ac3169eb478776e3a99e57c7b90e2c90048e1a4 /animism-align/frontend/app/views/episode/containers
parentd2cb17038b8537a609be06be2ed7013dbe27117e (diff)
adding episodes to projects
Diffstat (limited to 'animism-align/frontend/app/views/episode/containers')
-rw-r--r--animism-align/frontend/app/views/episode/containers/episode.edit.js20
-rw-r--r--animism-align/frontend/app/views/episode/containers/episode.new.js24
2 files changed, 40 insertions, 4 deletions
diff --git a/animism-align/frontend/app/views/episode/containers/episode.edit.js b/animism-align/frontend/app/views/episode/containers/episode.edit.js
index 4d7e270..8ba16ae 100644
--- a/animism-align/frontend/app/views/episode/containers/episode.edit.js
+++ b/animism-align/frontend/app/views/episode/containers/episode.edit.js
@@ -10,9 +10,25 @@ import EpisodeForm from '../components/episode.form'
import EpisodeMenu from '../components/episode.menu'
class EpisodeEdit extends Component {
+ state = {
+ project: {},
+ }
componentDidMount() {
+ this.ready()
+ }
+ componentDidUpdate(prevProps) {
+ if (this.props.project.lookup !== prevProps.project.lookup) {
+ this.ready()
+ }
+ }
+ ready() {
+ if (!this.props.project.lookup) return
console.log(this.props.match.params.id)
actions.episode.show(this.props.match.params.id)
+ .then(episode => {
+ const project = this.props.project.lookup[episode.project_id]
+ this.setState({ project })
+ })
}
handleSubmit(data) {
@@ -20,7 +36,7 @@ class EpisodeEdit extends Component {
.then(response => {
// response
console.log(response)
- history.push('/episode/')
+ history.push('/')
})
}
@@ -38,6 +54,7 @@ class EpisodeEdit extends Component {
<EpisodeMenu episodeActions={this.props.episodeActions} />
<EpisodeForm
data={show.res}
+ project={this.state.project}
onSubmit={this.handleSubmit.bind(this)}
/>
</div>
@@ -47,6 +64,7 @@ class EpisodeEdit extends Component {
const mapStateToProps = state => ({
episode: state.episode,
+ project: state.episode.index,
})
export default connect(mapStateToProps)(EpisodeEdit)
diff --git a/animism-align/frontend/app/views/episode/containers/episode.new.js b/animism-align/frontend/app/views/episode/containers/episode.new.js
index 42e9837..2ff279b 100644
--- a/animism-align/frontend/app/views/episode/containers/episode.new.js
+++ b/animism-align/frontend/app/views/episode/containers/episode.new.js
@@ -12,10 +12,26 @@ class EpisodeNew extends Component {
state = {
loading: true,
initialData: {},
+ project: {},
}
-
componentDidMount() {
- this.setState({ loading: false })
+ this.ready()
+ }
+ componentDidUpdate(prevProps) {
+ if (this.props.project.lookup !== prevProps.project.lookup) {
+ this.ready()
+ }
+ }
+ ready() {
+ if (!this.props.project.lookup) return
+ const { project_id } = this.props.match.params
+ const project = this.props.project.lookup[project_id]
+ this.setState({
+ loading: false,
+ initialData: { project_id },
+ project,
+ })
+ console.log(this.props.match.params.project_id)
}
handleSubmit(data) {
@@ -24,7 +40,7 @@ class EpisodeNew extends Component {
.then(res => {
console.log(res)
if (res.res && res.res.id) {
- history.push('/episode/')
+ history.push('/')
}
})
.catch(err => {
@@ -44,6 +60,7 @@ class EpisodeNew extends Component {
<EpisodeForm
isNew
data={this.state.initialData}
+ project={this.state.project}
onSubmit={this.handleSubmit.bind(this)}
/>
</div>
@@ -53,6 +70,7 @@ class EpisodeNew extends Component {
const mapStateToProps = state => ({
episode: state.episode,
+ project: state.project.index,
})
const mapDispatchToProps = dispatch => ({