<commit_before>import loadTemplate from '../../utils/loadTemplate';
import app from '../../app';
import Profile from '../../models/profile/Profile';
import SocialBtns from '../components/SocialBtns';
import BaseModal from './BaseModal';
import { getLangByCode } from '../../data/languages';
import VerifiedMod from '../components/VerifiedMod';

export default class extends BaseModal {
  constructor(options = {}) {
    const opts = {
      removeOnClose: true,
      ...options,
    };

    super(opts);
    this.options = opts;

    if (!this.model || !(this.model instanceof Profile)) {
      throw new Error('Please provide a Profile model.');
    }
  }

  className() {
    return `${super.className()} moderatorDetails modalTop modalScrollPage modalNarrow`;
  }

  events() {
    return {
      'click .js-addAsModerator': 'addAsModerator',
      ...super.events(),
    };
  }

  addAsModerator() {
    this.trigger('addAsModerator');
    this.close();
  }

  render() {
    const modLanguages = this.model.get('moderatorInfo')
      .get('languages')
      .map(lang => {
        const langData = getLangByCode(lang);
        return langData && langData.name || lang;
      });

    const verifiedMod = app.verifiedMods.get(this.model.get('peerID'));

    loadTemplate('modals/moderatorDetails.html', (t) => {
      this.$el.html(t({
        followedByYou: this.followedByYou,
        displayCurrency: app.settings.get('localCurrency'),
        ownMod: app.settings.get('storeModerators').indexOf(this.model.id) !== -1,
        purchase: this.options.purchase,
        cardState: this.options.cardState,
        modLanguages,
        verifiedMod,
        ...this.model.toJSON(),
      }));
      super.render();

      this.$followBtn = this.$('.js-follow');
      this.$unFollowBtn = this.$('.js-unFollow');

      if (this.socialBtns) this.socialBtns.remove();
      this.socialBtns = this.createChild(SocialBtns, {
        targetID: this.model.id,
        initialState: {
          stripClasses: 'flexHCent gutterH',
          btnClasses: 'clrP clrBr clrSh2',
        },
      });
      this.$('.js-socialBtns').append(this.socialBtns.render().$el);

      if (this.verifiedMod) this.verifiedMod.remove();
      this.verifiedMod = this.createChild(VerifiedMod, {
        model: verifiedMod,
        data: app.verifiedMods.data,
        showLongText: true,
      });
      this.getCachedEl('.js-verifiedMod').append(this.verifiedMod.render().el);
    });

    return this;
  }
}
<commit_msg>Refresh moderator details on verifiedMods update<commit_after>import loadTemplate from '../../utils/loadTemplate';
import app from '../../app';
import Profile from '../../models/profile/Profile';
import SocialBtns from '../components/SocialBtns';
import BaseModal from './BaseModal';
import { getLangByCode } from '../../data/languages';
import VerifiedMod from '../components/VerifiedMod';

export default class extends BaseModal {
  constructor(options = {}) {
    const opts = {
      removeOnClose: true,
      ...options,
    };

    super(opts);
    this.options = opts;

    if (!this.model || !(this.model instanceof Profile)) {
      throw new Error('Please provide a Profile model.');
    }
    
    this.verifiedModModel = app.verifiedMods.get(this.model.get('peerID'));

    this.listenTo(app.verifiedMods, 'update', () => {
      const nowIsVerifiedMod = app.verifiedMods.get(this.model.get('peerID'));
      if (nowIsVerifiedMod !== this.verifiedModModel) {
        this.verifiedModModel = nowIsVerifiedMod;
        this.render();
      }
    });

  }

  className() {
    return `${super.className()} moderatorDetails modalTop modalScrollPage modalNarrow`;
  }

  events() {
    return {
      'click .js-addAsModerator': 'addAsModerator',
      ...super.events(),
    };
  }

  addAsModerator() {
    this.trigger('addAsModerator');
    this.close();
  }

  render() {
    const modLanguages = this.model.get('moderatorInfo')
      .get('languages')
      .map(lang => {
        const langData = getLangByCode(lang);
        return langData && langData.name || lang;
      });

    loadTemplate('modals/moderatorDetails.html', (t) => {
      this.$el.html(t({
        followedByYou: this.followedByYou,
        displayCurrency: app.settings.get('localCurrency'),
        ownMod: app.settings.get('storeModerators').indexOf(this.model.id) !== -1,
        purchase: this.options.purchase,
        cardState: this.options.cardState,
        modLanguages,
        verifiedMod: this.verifiedModModel,
        ...this.model.toJSON(),
      }));
      super.render();

      this.$followBtn = this.$('.js-follow');
      this.$unFollowBtn = this.$('.js-unFollow');

      if (this.socialBtns) this.socialBtns.remove();
      this.socialBtns = this.createChild(SocialBtns, {
        targetID: this.model.id,
        initialState: {
          stripClasses: 'flexHCent gutterH',
          btnClasses: 'clrP clrBr clrSh2',
        },
      });
      this.$('.js-socialBtns').append(this.socialBtns.render().$el);

      if (this.verifiedMod) this.verifiedMod.remove();
      this.verifiedMod = this.createChild(VerifiedMod, {
        model: this.verifiedModModel,
        data: app.verifiedMods.data,
        showLongText: true,
      });
      this.getCachedEl('.js-verifiedMod').append(this.verifiedMod.render().el);
    });

    return this;
  }
}

{'fraction_non_alphanumeric': 0.1553398058252427, 'fraction_numerical': 0.0007468259895444362, 'mean_word_length': 2.7098337950138505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '3850279', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1669, 'n_words': 292}