<commit_before>/** @jsx React.DOM */

var Firebase    = require('firebase');
var moment      = require('moment');
var randomColor = require('randomcolor');
var React       = require('react');
require('react/addons');

var Router = require('react-router');
var Routes = Router.Routes;
var Route  = Router.Route;
var Link   = Router.Link;

function transformSnapshotToNote(snapshot) {
  var note = snapshot.val();
  note.name = snapshot.name();
  note.createdAt = new Date(note.createdAt);
  note.localHidden = note.hidden;
  note.style = { background: randomColor({luminosity: 'light'}) };
  return note;
}

function escapeRegexp(str) {
  return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}

var Note = React.createClass({
  toggleLocalHidden: function(e) {
    if (window.getSelection().toString() || e.target.tagName.match(/^[ai]$/i)) return;
    this.props.onToggleLocalHidden();
  },

  render: function() {
    var note = this.props.note;
    var cx = React.addons.classSet;
    var noteContentClasses = cx({
      'note-content': true,
      'hidden': note.localHidden,
    });

    return (
      <li className="note" onClick={this.toggleLocalHidden} style={note.style}>
        <div className="controls">
          <time>{moment(note.createdAt).fromNow().replace(' ago', '')}</time>
          <div className="icons">
            <a href="#" onClick={this.props.onToggleHidden}>{note.hidden ? '☼' : '☀'}</a>
            <a href="#" className="delete-note" onClick={this.props.onDelete}>✖</a>
          </div>
        </div>
        <div className={noteContentClasses}>
          {note.content}
        </div>
      </li>
    );
  }
});

var Index = React.createClass({
  mixins: [React.addons.LinkedStateMixin, AuthenticatedRoute],

  getInitialState: function() {
    return { notes: [], newNote: '', filter: '' };
  },

  componentWillMount: function() {
    this.firebaseRef = firebaseRef.child('notes');

    this.firebaseRef.on('child_added', function(snapshot) {
      this.state.notes.push(transformSnapshotToNote(snapshot));
      this.state.notes.sort(function(a, b) {
        return a.createdAt > b.createdAt ? -1 : 1;
      });
      this.setState({ notes: this.state.notes });
    }.bind(this));

    this.firebaseRef.on('child_removed', function(snapshot) {
      var snapshotName = snapshot.name();
      var newNotesList = this.state.notes.filter(function(note) {
        return note.name !== snapshotName;
      });
      this.setState({ notes: newNotesList });
    }.bind(this));

    this.firebaseRef.on('child_changed', function(snapshot) {
      var snapshotName = snapshot.name();
      var note, i;
      for (i = 0; i < this.state.notes.length; i++) {
        if (this.state.notes[i].name === snapshotName) {
          note = this.state.notes[i];
          break;
        }
      }
      note.hidden = note.localHidden = snapshot.val().hidden;
      this.setState({ notes: this.state.notes });
    }.bind(this));
  },

  updateNewNote: function() {
    this.setState({ newNote: this.refs.textarea.getDOMNode().value });
  },

  submitNewNote: function() {
    if (!this.state.newNote) {
      return;
    }

    this.firebaseRef.push({
      content: this.state.newNote,
      createdAt: (new Date()).toISOString(),
      hidden: false,
    });

    this.setState({ newNote: '' });
  },

  handleKeyDown: function(e) {
    if (e.keyCode == 13 && e.ctrlKey) {
      this.submitNewNote();
    }
  },

  toggleLocalHidden: function(note) {
    note.localHidden = !note.localHidden;
    this.setState({ notes: this.state.notes });
  },

  toggleHidden: function(note) {
    this.firebaseRef.child(note.name).update({ hidden: !note.hidden });
  },

  delete: function(note) {
    this.firebaseRef.child(note.name).remove();
  },

  render: function() {
    var notes = this.state.notes;

    if (this.state.filter) {
      var filterRegexp = new RegExp(escapeRegexp(this.state.filter), 'i');<commit_msg>prevent newline from ctrl+enter when submitting new note<commit_after>/** @jsx React.DOM */

var Firebase    = require('firebase');
var moment      = require('moment');
var randomColor = require('randomcolor');
var React       = require('react');
require('react/addons');

var Router = require('react-router');
var Routes = Router.Routes;
var Route  = Router.Route;
var Link   = Router.Link;

function transformSnapshotToNote(snapshot) {
  var note = snapshot.val();
  note.name = snapshot.name();
  note.createdAt = new Date(note.createdAt);
  note.localHidden = note.hidden;
  note.style = { background: randomColor({luminosity: 'light'}) };
  return note;
}

function escapeRegexp(str) {
  return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}

var Note = React.createClass({
  toggleLocalHidden: function(e) {
    if (window.getSelection().toString() || e.target.tagName.match(/^[ai]$/i)) return;
    this.props.onToggleLocalHidden();
  },

  render: function() {
    var note = this.props.note;
    var cx = React.addons.classSet;
    var noteContentClasses = cx({
      'note-content': true,
      'hidden': note.localHidden,
    });

    return (
      <li className="note" onClick={this.toggleLocalHidden} style={note.style}>
        <div className="controls">
          <time>{moment(note.createdAt).fromNow().replace(' ago', '')}</time>
          <div className="icons">
            <a href="#" onClick={this.props.onToggleHidden}>{note.hidden ? '☼' : '☀'}</a>
            <a href="#" className="delete-note" onClick={this.props.onDelete}>✖</a>
          </div>
        </div>
        <div className={noteContentClasses}>
          {note.content}
        </div>
      </li>
    );
  }
});

var Index = React.createClass({
  mixins: [React.addons.LinkedStateMixin, AuthenticatedRoute],

  getInitialState: function() {
    return { notes: [], newNote: '', filter: '' };
  },

  componentWillMount: function() {
    this.firebaseRef = firebaseRef.child('notes');

    this.firebaseRef.on('child_added', function(snapshot) {
      this.state.notes.push(transformSnapshotToNote(snapshot));
      this.state.notes.sort(function(a, b) {
        return a.createdAt > b.createdAt ? -1 : 1;
      });
      this.setState({ notes: this.state.notes });
    }.bind(this));

    this.firebaseRef.on('child_removed', function(snapshot) {
      var snapshotName = snapshot.name();
      var newNotesList = this.state.notes.filter(function(note) {
        return note.name !== snapshotName;
      });
      this.setState({ notes: newNotesList });
    }.bind(this));

    this.firebaseRef.on('child_changed', function(snapshot) {
      var snapshotName = snapshot.name();
      var note, i;
      for (i = 0; i < this.state.notes.length; i++) {
        if (this.state.notes[i].name === snapshotName) {
          note = this.state.notes[i];
          break;
        }
      }
      note.hidden = note.localHidden = snapshot.val().hidden;
      this.setState({ notes: this.state.notes });
    }.bind(this));
  },

  updateNewNote: function() {
    this.setState({ newNote: this.refs.textarea.getDOMNode().value });
  },

  submitNewNote: function() {
    if (!this.state.newNote) {
      return;
    }

    this.firebaseRef.push({
      content: this.state.newNote,
      createdAt: (new Date()).toISOString(),
      hidden: false,
    });

    this.setState({ newNote: '' });
  },

  handleKeyDown: function(e) {
    if (e.keyCode == 13 && e.ctrlKey) {
      this.submitNewNote();
      e.preventDefault(); // prevents new line from pressing enter
    }
  },

  toggleLocalHidden: function(note) {
    note.localHidden = !note.localHidden;
    this.setState({ notes: this.state.notes });
  },

  toggleHidden: function(note) {
    this.firebaseRef.child(note.name).update({ hidden: !note.hidden });
  },

  delete: function(note) {
    this.firebaseRef.child(note.name).remove();
  },

  render: function() {
    var notes = this.state.notes;

    if (this.state.filter) {
      var filterRegexp = new RegExp(escapeRegexp(this.state.filter), 'i');
{'fraction_non_alphanumeric': 0.17566891722930733, 'fraction_numerical': 0.001250312578144536, 'mean_word_length': 2.946225949679329, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '6110928', 'n_tokens_mistral': 2585, 'n_tokens_neox': 2548, 'n_words': 471}