Skip to content

Commit

Permalink
[Fix #62] Refactor for readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
LaChope committed Nov 12, 2021
1 parent 6bda35a commit c3c253e
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/components/Question.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export default class Question extends React.Component {
);
}

static evaluateIcon(icon, question, options, onCommentChange) {
static getIconComponent(icon, question, options, onCommentChange) {
if (icon && icon.behavior === Constants.ICON_BEHAVIOR.ENABLE) {
if (icon.id === Constants.ICONS.QUESTION_HELP && question[Constants.HELP_DESCRIPTION]) {
return <HelpIcon
Expand All @@ -330,26 +330,19 @@ export default class Question extends React.Component {
}

static getIconFromIconList = (iconList, iconName) => {
let icon;

for (let i = 0; i < iconList.length; i++) {
if (iconList[i].id === iconName) {
icon = iconList[i];
}
}
return icon;
return iconList.find(icon => icon.id === iconName);
}

static renderQuestionHelp(question, options) {
const icons = options.icons;
const questionHelpIcon = this.getIconFromIconList(icons, Constants.ICONS.QUESTION_HELP)
return this.evaluateIcon(questionHelpIcon, question, options);
return this.getIconComponent(questionHelpIcon, question, options);
}

static renderQuestionComments = (question, options, onCommentChange) => {
const icons = options.icons;
const questionCommentsIcon = this.getIconFromIconList(icons, Constants.ICONS.QUESTION_COMMENTS)
return this.evaluateIcon(questionCommentsIcon, question, options, onCommentChange);
return this.getIconComponent(questionCommentsIcon, question, options, onCommentChange);
}

static renderIcons(question, options, onCommentChange) {
Expand Down

0 comments on commit c3c253e

Please sign in to comment.