Skip to content

Commit

Permalink
Editor does not need to maintain a local state
Browse files Browse the repository at this point in the history
Just use the props
  • Loading branch information
jcoyne committed Jun 17, 2019
1 parent 6c99ebf commit 3d83ed2
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions src/components/editor/Editor.jsx
Expand Up @@ -14,33 +14,16 @@ import ErrorMessages from './ErrorMessages'
import { getCurrentSession, getCurrentUser } from 'authSelectors'
import { publishRDFResource } from 'sinopiaServer'

const _ = require('lodash')

/**
* This is the root component of the resource edit page
*/
class Editor extends Component {
constructor(props) {
super(props)
this.state = {
resourceTemplateId: '',
}
}

componentDidMount() {
if (this.props.location.state !== undefined) {
this.setState({
resourceTemplateId: this.props.location.state.resourceTemplateId,
})
} else {
if (!this.props.location.state) {
this.props.history.push('/templates')
}
}

renderResourceTemplate = () => (
<ResourceTemplate resourceTemplateId = {this.state.resourceTemplateId} />
)

chooseGroupThenSave = (rdf, group) => {
const request = publishRDFResource(this.props.currentUser, rdf, group)

Expand Down Expand Up @@ -79,7 +62,7 @@ class Editor extends Component {
<ErrorMessages />
<GroupChoiceModal close={ this.closeGroupChooser } save={ this.chooseGroupThenSave } />

{ _.isEmpty(this.state.resourceTemplateId) ? (<div>Loading resource template...</div>) : this.renderResourceTemplate() }
<ResourceTemplate resourceTemplateId = {this.props.location.state.resourceTemplateId} />
</div>
)
}
Expand Down

0 comments on commit 3d83ed2

Please sign in to comment.