{"size": 1475, "ext": "js", "max_stars_repo_path": "app/imports/ui/components/shared/user-answers-component.js", "max_stars_repo_name": "radgrad/radgrad", "max_stars_repo_stars_event_min_datetime": "2016-10-24T05:23:29.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-09T19:22:17.000Z", "max_issues_repo_path": "app/imports/ui/components/shared/user-answers-component.js", "max_issues_repo_name": "radgrad/radgrad", "max_issues_repo_issues_event_min_datetime": "2015-11-10T16:02:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T18:20:16.000Z", "max_forks_repo_path": "app/imports/ui/components/shared/user-answers-component.js", "max_forks_repo_name": "radgrad/radgrad", "max_forks_repo_forks_event_min_datetime": "2016-10-24T03:45:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-08T18:27:53.000Z"}
{"max_stars_count": 12, "max_issues_count": 360, "max_forks_count": 7, "avg_line_length": 29.5, "max_line_length": 86, "alphanum_fraction": 0.6705084746}
import { Template } from 'meteor/templating';
import { MentorAnswers } from '../../../api/mentor/MentorAnswerCollection';
import { MentorQuestions } from '../../../api/mentor/MentorQuestionCollection';
import { getRouteUserName } from './route-user-name';
import { getGroupName } from './route-group-name';

function getAnswers(mentorID) {
  return MentorAnswers.find({ mentorID }).fetch();
}

Template.User_Answers_Component.helpers({
  count() {
    if (Template.instance().userID) {
      const { userID } = Template.instance();
      return getAnswers(userID).length;
    }
    return 0;
  },
  questionName(answer) {
    const question = MentorQuestions.findDoc(answer.questionID);
    return question.question;
  },
  answers() {
    if (Template.instance().userID) {
      const { userID } = Template.instance();
      return getAnswers(userID);
    }
    return null;
  },
  questionURL() {
    const group = getGroupName();
    if (group === 'student') {
      return `/student/${getRouteUserName()}/mentor-space`;
    } if (group === 'faculty') {
      return `/mentor/${getRouteUserName()}/mentor-space`;
    }
    return `/mentor/${getRouteUserName()}/mentor-space`;
  },
});

Template.User_Answers_Component.onCreated(function userAnswersComponentOnCreated() {
  if (this.data.userID) {
    this.userID = this.data.userID;
  }
});

Template.User_Answers_Component.onRendered(function userAnswersComponentOnRendered() {
  this.$('.ui.accordion').accordion();
});
