<commit_before>import { Template } from 'meteor/templating';
import { _ } from 'meteor/erasaur:meteor-lodash';
import { Teasers } from '../../../api/teaser/TeaserCollection.js';
import { Interests } from '../../../api/interest/InterestCollection.js';
import { Opportunities } from '../../../api/opportunity/OpportunityCollection';
import { Slugs } from '../../../api/slug/SlugCollection.js';
import { getRouteUserName } from '../shared/route-user-name';
import { Users } from '../../../api/user/UserCollection.js';
import * as RouteNames from '/imports/startup/client/router.js';

Template.Student_Teaser_Widget.onCreated(function studentTeaserWidgetOnCreated() {
  this.subscribe(Teasers.getPublicationName());
  this.subscribe(Interests.getPublicationName());
});

function matchingTeasers() {
  const allTeasers = Teasers.find().fetch();
  const matching = [];
  const user = Users.findDoc({ username: getRouteUserName() });
  const userInterests = [];
  let teaserInterests = [];
  _.map(Users.getInterestIDs(user._id), (id) => {
    userInterests.push(Interests.findDoc(id));
  });
  _.map(allTeasers, (teaser) => {
    teaserInterests = [];
    _.map(teaser.interestIDs, (id) => {
      teaserInterests.push(Interests.findDoc(id));
      _.map(teaserInterests, (teaserInterest) => {
        _.map(userInterests, (userInterest) => {
          if (_.isEqual(teaserInterest, userInterest)) {
            if (!_.includes(matching, teaser)) {
              matching.push(teaser);
            }
          }
        });
      });
    });
  });
  return matching;
}

Template.Student_Teaser_Widget.helpers({
  opportunitiesRouteName() {
    return RouteNames.studentExplorerOpportunitiesPageRouteName;
  },
  opportunitySlug(teaser) {
    let ret;
    if (teaser.opportunityID) {
      ret = Slugs.findDoc(Opportunities.findDoc(teaser.opportunityID).slugID).name;
    } else {
      ret = '#';
    }
    return ret;
  },
  teaserAuthor(teaser) {
    return teaser.author;
  },
  teaserCount() {
    return matchingTeasers().length;
  },
  teasers() {
    return matchingTeasers();
  },
  teaserTitle(teaser) {
    return teaser.title;
  },
  teaserUrl(teaser) {
    return teaser.url;
  },
});

Template.Student_Teaser_Widget.events({
  // placeholder: if you add a form to this top-level layout, handle the associated events here.
});

Template.Student_Teaser_Widget.onRendered(function enableVideo() {
  setTimeout(() => {
    this.$('.ui.embed').embed();
  }, 300);
});<commit_msg>It seems like the teasers on the student home page always load now. Though you have to wait a few seconds.<commit_after>import { Template } from 'meteor/templating';
import { _ } from 'meteor/erasaur:meteor-lodash';
import { Teasers } from '../../../api/teaser/TeaserCollection.js';
import { Interests } from '../../../api/interest/InterestCollection.js';
import { Opportunities } from '../../../api/opportunity/OpportunityCollection';
import { Slugs } from '../../../api/slug/SlugCollection.js';
import { getRouteUserName } from '../shared/route-user-name';
import { Users } from '../../../api/user/UserCollection.js';
import * as RouteNames from '/imports/startup/client/router.js';

Template.Student_Teaser_Widget.onCreated(function studentTeaserWidgetOnCreated() {
  this.subscribe(Teasers.getPublicationName());
  this.subscribe(Interests.getPublicationName());
});

function matchingTeasers() {
  const allTeasers = Teasers.find().fetch();
  const matching = [];
  const user = Users.findDoc({ username: getRouteUserName() });
  const userInterests = [];
  let teaserInterests = [];
  _.map(Users.getInterestIDs(user._id), (id) => {
    userInterests.push(Interests.findDoc(id));
  });
  _.map(allTeasers, (teaser) => {
    teaserInterests = [];
    _.map(teaser.interestIDs, (id) => {
      teaserInterests.push(Interests.findDoc(id));
      _.map(teaserInterests, (teaserInterest) => {
        _.map(userInterests, (userInterest) => {
          if (_.isEqual(teaserInterest, userInterest)) {
            if (!_.includes(matching, teaser)) {
              matching.push(teaser);
            }
          }
        });
      });
    });
  });
  return matching;
}

Template.Student_Teaser_Widget.helpers({
  opportunitiesRouteName() {
    return RouteNames.studentExplorerOpportunitiesPageRouteName;
  },
  opportunitySlug(teaser) {
    let ret;
    if (teaser.opportunityID) {
      ret = Slugs.findDoc(Opportunities.findDoc(teaser.opportunityID).slugID).name;
    } else {
      ret = '#';
    }
    return ret;
  },
  teaserAuthor(teaser) {
    return teaser.author;
  },
  teaserCount() {
    return matchingTeasers().length;
  },
  teasers() {
    return matchingTeasers();
  },
  teaserTitle(teaser) {
    return teaser.title;
  },
  teaserUrl(teaser) {
    return teaser.url;
  },
});

Template.Student_Teaser_Widget.events({
  // placeholder: if you add a form to this top-level layout, handle the associated events here.
});

Template.Student_Teaser_Widget.onRendered(function enableVideo() {
  setTimeout(() => {
    this.$('.ui.embed').embed('show');
  }, 300);
});
{'fraction_non_alphanumeric': 0.1603792218052538, 'fraction_numerical': 0.0011850681414181316, 'mean_word_length': 3.4149956408020925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4261737', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1598, 'n_words': 278}