From ad26a7fb2b7a40763a4948af5161e8e8c338568c Mon Sep 17 00:00:00 2001 From: Devin Howard Date: Sat, 28 Jan 2017 15:52:00 -0500 Subject: [PATCH] prevent editing on desc/title if not authorized to edit --- frontend/src/components/TopicCard/Desc.js | 14 +++++- frontend/src/components/TopicCard/Title.js | 53 +++++++++++++--------- frontend/src/components/TopicCard/index.js | 5 +- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/frontend/src/components/TopicCard/Desc.js b/frontend/src/components/TopicCard/Desc.js index 2cb665cb..db17a6b7 100644 --- a/frontend/src/components/TopicCard/Desc.js +++ b/frontend/src/components/TopicCard/Desc.js @@ -31,8 +31,7 @@ class Desc extends Component { ? '' : Util.mdToHTML(this.props.desc) - const htmlSpan = - + if (this.props.authorizedToEdit) { return (
@@ -58,6 +57,17 @@ class Desc extends Component {
) + } else { + return ( +
+
+ + {this.props.desc} + +
+
+ ) + } } } diff --git a/frontend/src/components/TopicCard/Title.js b/frontend/src/components/TopicCard/Title.js index 4981b561..77f153b4 100644 --- a/frontend/src/components/TopicCard/Title.js +++ b/frontend/src/components/TopicCard/Title.js @@ -2,32 +2,43 @@ import React from 'react' import { RIETextArea } from 'riek' const Title = (props) => { - return ( - - { - const ENTER = 13 - if (e.which === ENTER) { - e.preventDefault() - props.onChange({ name: e.target.value }) - } - } - }} - /> - - ) + if (props.authorizedToEdit) { + return ( + + { + const ENTER = 13 + if (e.which === ENTER) { + e.preventDefault() + props.onChange({ name: e.target.value }) + } + } + }} + /> + + ) + } else { + return ( + + + {props.name} + + + ) + } } /* * Title.propTypes = { * name: PropTypes.string, - * onChange: PropTypes.func + * onChange: PropTypes.func, + * authorizedToEdit: PropTypes.bool * } */ diff --git a/frontend/src/components/TopicCard/index.js b/frontend/src/components/TopicCard/index.js index 8af548c7..9b8a2940 100644 --- a/frontend/src/components/TopicCard/index.js +++ b/frontend/src/components/TopicCard/index.js @@ -23,7 +23,10 @@ class ReactTopicCard extends Component { return (
- + <Title name={topic.get('name')} + onChange={this.props.updateTopic} + authorizedToEdit={topic.authorizeToEdit(ActiveMapper)} + /> <Links topic={topic} ActiveMapper={this.props.ActiveMapper} updateTopic={this.props.updateTopic}