Skip to content

Commit

Permalink
[Upd #65] Refactor icons processing
Browse files Browse the repository at this point in the history
  • Loading branch information
blcham committed Nov 29, 2021
1 parent 0ea71b8 commit f1d7106
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/components/Question.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {CaretSquareDown, CaretSquareUp, InfoCircle} from '../styles/icons';
import {ConfigurationContext} from '../contexts/ConfigurationContext';
import classNames from 'classnames';
import QuestionCommentIcon from "./comment/QuestionCommentIcon";
import ExternalLink from "../styles/icons/ExternalLink";
import LinkIcon from "./LinkIcon";

// TODO Remove once the pretty layout is tested
const PRETTY_ANSWERABLE_LAYOUT = true;
Expand Down Expand Up @@ -376,28 +378,18 @@ export default class Question extends React.Component {
return null;
}

static getIconComponentFromName(iconName, question, options, onCommentChange, showIcon) {
const iconList = (options.icons) ? options.icons : Constants.DEFAULT_OPTIONS.icons;
const icon = this.getIconFromIconList(iconList, iconName);
return this.getIconComponent(icon, question, options, onCommentChange, showIcon);
}

static renderQuestionHelp(question, options, onCommentChange, showIcon) {
const icons = options.icons;
let questionHelpIcon;
if (!icons) {
questionHelpIcon = Constants.DEFAULT_OPTIONS.icons.find(icon => {
return icon.id === Constants.ICONS.QUESTION_HELP
});
}
else questionHelpIcon = this.getIconFromIconList(icons, Constants.ICONS.QUESTION_HELP);
return this.getIconComponent(questionHelpIcon, question, options, onCommentChange, showIcon);
return this.getIconComponentFromName(Constants.ICONS.QUESTION_HELP, question, options, onCommentChange, showIcon);
}

static renderQuestionComments = (question, options, onCommentChange, showIcon) => {
const icons = options.icons;
let questionCommentsIcon;
if (!icons) {
questionCommentsIcon = Constants.DEFAULT_OPTIONS.icons.find(icon => {
return icon.id === Constants.ICONS.QUESTION_COMMENTS
});
}
else questionCommentsIcon = this.getIconFromIconList(icons, Constants.ICONS.QUESTION_COMMENTS);
return this.getIconComponent(questionCommentsIcon, question, options, onCommentChange, showIcon);
return this.getIconComponentFromName(Constants.ICONS.QUESTION_COMMENTS, question, options, onCommentChange, showIcon);
}

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

0 comments on commit f1d7106

Please sign in to comment.