<commit_before>Template.inviteFriends.events({
  "submit form": function (event, template) {
    var game = this;
    event.preventDefault();
    Alerts.clearSeen({where: "inviteFriends"});
    var friends = Friends.makeFriends(template.findAll("input.friend-name"),
                              template.findAll("input.friend-email"));
    if (_.isEmpty(friends)) {
      Alerts.throw({message: "Even imaginary friends have names",
                    type: "danger", where: "inviteFriends"});
      return;
    }
    if (! Alerts.test(Alertables.inviteFriends(friends),
                      {type: "danger", where: "inviteFriends"})) {
      return;
    }
    Meteor.call(
      "dev.inviteFriends", game._id, friends, function (error, result) {
        if (!error) {
          Alerts.throw({
            message: "Your friend has been sent an invitation :)",
            type: "success", where: game._id
          });
          Session.set("invite-friends", null);
          window.scrollTo(0,0);
        } else {
          // typical error: email in use
          // BUT we're currently allowing users to add friends
          // that are existing users...
          console.log(error);
          if (error instanceof Meteor.Error) {
            Alerts.throw({
              message: error.reason,
              type: "danger", where: "inviteFriends"
            });
          } else {
            Alerts.throw({
              message: "Hmm, something went wrong. Try again?",
              type: "danger", where: "inviteFriends"
            });
          }
        }
      });
  },
  "click .add-friends .close": function () {
    Session.set("invite-friends", null);
  }
});

Template.inviteFriends.destroyed = function () {
  Notifications.remove({where: "inviteFriends"});
};

Template.inviteFriends.helpers({
  numFriends: function() {
    return FriendsToAdd.find().count();
  }
});<commit_msg>Fixed slow submit for inviting a friend(s). Uses the same pattern as game-on fix. Update UI first and then let the email sending occur after.<commit_after>Template.inviteFriends.events({
  "submit form": function (event, template) {
    var game = this;
    event.preventDefault();
    Alerts.clearSeen({where: "inviteFriends"});
    var friends = Friends.makeFriends(template.findAll("input.friend-name"),
                              template.findAll("input.friend-email"));
    if (_.isEmpty(friends)) {
      Alerts.throw({message: "Even imaginary friends have names",
                    type: "danger", where: "inviteFriends"});
      return;
    }
    if (! Alerts.test(Alertables.inviteFriends(friends),
                      {type: "danger", where: "inviteFriends"})) {
      return;
    }

    Alerts.throw({
      message: "Your friend has been sent an invitation :)",
      type: "success", where: game._id
    });
    Session.set("invite-friends", null);
    window.scrollTo(0,0);

    Meteor.call(
      "dev.inviteFriends", game._id, friends, function (error, result) {
        if (error) {
          // typical error: email in use
          // BUT we're currently allowing users to add friends
          // that are existing users...
          console.log(error);
          if (error instanceof Meteor.Error) {
            Alerts.throw({
              message: error.reason,
              type: "danger", where: game._id
            });
          } else {
            Alerts.throw({
              message: "Hmm, something went wrong while inviting a friend. Try again?",
              type: "danger", where: game._id
            });
          }
        }
      });
  },
  "click .add-friends .close": function () {
    Session.set("invite-friends", null);
  }
});

Template.inviteFriends.destroyed = function () {
  Notifications.remove({where: "inviteFriends"});
};

Template.inviteFriends.helpers({
  numFriends: function() {
    return FriendsToAdd.find().count();
  }
});
{'fraction_non_alphanumeric': 0.13724987172909184, 'fraction_numerical': 0.001026167265264238, 'mean_word_length': 2.124198717948718, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, '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': '6949564', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1084, 'n_words': 265}