<commit_before>"use strict";
import React, { Component, PropTypes } from 'react';
import { Link } from 'react-router';
import { getItem, postUnsubscribe } from '../../actions';
import PageHeader from '../../components/PageHeader';
import Loading from '../../components/Loading';
import Stored from '../../components/Stored';
import TrashIcon from '../../icons/Trash';

class EmailList extends Component {

  constructor () {
    super();
    this._onSearch = this._onSearch.bind(this);
    this.state = { addresses: [] };
  }

  componentDidMount () {
    document.title = this.props.title;
    this._setStateFromLocation(this.props);
    this._loadEmailList();
  }

  componentWillReceiveProps (nextProps) {
    this._setStateFromLocation(nextProps);
  }

  _setStateFromLocation (props) {
    const { emailList } = this.state;
    const searchText = props.location.query.search || '';
    let addresses = (emailList || {}).addresses || [];
    if (searchText) {
      const exp = new RegExp(searchText, 'i');
      addresses = addresses.filter(a => (
        exp.test(a.address) || (a.userId && exp.test(a.userId.name))
      ));
    }
    this.setState({ addresses, searchText });
  }

  _loadEmailList () {
    const { params: { id } } = this.props;
    const { searchText } = this.state;
    getItem('email-lists', id)
    .then(emailList => {
      let addresses = emailList.addresses;
      if (searchText) {
        const exp = new RegExp(searchText, 'i');
        addresses = addresses.filter(a => exp.test(a));
      }
      this.setState({ addresses, emailList });
    })
    .catch(error => console.log('!!! EmailList catch', error));<commit_msg>Set EmailList document title.<commit_after>"use strict";
import React, { Component, PropTypes } from 'react';
import { Link } from 'react-router';
import { getItem, postUnsubscribe } from '../../actions';
import PageHeader from '../../components/PageHeader';
import Loading from '../../components/Loading';
import Stored from '../../components/Stored';
import TrashIcon from '../../icons/Trash';

class EmailList extends Component {

  constructor () {
    super();
    this._onSearch = this._onSearch.bind(this);
    this.state = { addresses: [] };
  }

  componentDidMount () {
    this._setStateFromLocation(this.props);
    this._loadEmailList();
  }

  componentWillReceiveProps (nextProps) {
    this._setStateFromLocation(nextProps);
  }

  _setStateFromLocation (props) {
    const { emailList } = this.state;
    const searchText = props.location.query.search || '';
    let addresses = (emailList || {}).addresses || [];
    if (searchText) {
      const exp = new RegExp(searchText, 'i');
      addresses = addresses.filter(a => (
        exp.test(a.address) || (a.userId && exp.test(a.userId.name))
      ));
    }
    this.setState({ addresses, searchText });
  }

  _loadEmailList () {
    const { params: { id } } = this.props;
    const { searchText } = this.state;
    getItem('email-lists', id)
    .then(emailList => {
      let addresses = emailList.addresses;
      if (searchText) {
        const exp = new RegExp(searchText, 'i');
        addresses = addresses.filter(a => exp.test(a));
      }
      this.setState({ addresses, emailList });
      document.title = emailList.name;
    })
    .catch(error => console.log('!!! EmailList catch', error));
{'fraction_non_alphanumeric': 0.16146458583433373, 'fraction_numerical': 0.0, 'mean_word_length': 3.0547445255474455, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '4650448', 'n_tokens_mistral': 974, 'n_tokens_neox': 991, 'n_words': 222}