<commit_before>import React, { Component } from 'react';

// Controls
import { RIETextArea } from 'riek';
import Dialog  from 'material-ui/Dialog';
import FlatButton from 'material-ui/FlatButton';

// Utils
import axios from 'axios';
import Utils from 'utils';

/*
 * A single Agendum Note.
 */
export default class AgendumNote extends Component {
    constructor(props) {
        super(props);
        this.state = { note: props.note };
    }

    /*
     * Handle adding a new note to the agendum.
     */
    addNewNote = (prop) => {
        var url = `/meetings/${this.props.meetingID}/agenda/${this.props.agendumID}/notes`;

        // Create the new note
        axios.post(url, { 
            authenticity_token: Utils.getAuthenticityToken(), 
            agendum_note: prop 
        }).then(response => {
            this.props.handleNewNote(response.data);
        });
    }

    render() {
        var isExisting = this.state.note.id;

        var noteClass = 'collection-item' + 
            (!isExisting ? ' grey-text' : '');

        return(
            <li className={noteClass}>
                <RIETextArea
                    change={this.addNewNote}
                    value={isExisting ? this.state.note.content : 'Add a new note...'}
                    propName="content" />
            </li>
        );
    }
}<commit_msg>Handle updating of existing notes.<commit_after>import React, { Component } from 'react';

// Controls
import { RIETextArea } from 'riek';
import Dialog  from 'material-ui/Dialog';
import FlatButton from 'material-ui/FlatButton';

// Utils
import axios from 'axios';
import Utils from 'utils';

/*
 * A single Agendum Note.
 */
export default class AgendumNote extends Component {
    constructor(props) {
        super(props);
        this.state = { note: props.note };
    }

    /*
     * Handle adding a new note to the agendum.
     */
    addNewNote = (prop) => {
        var url = `/meetings/${this.props.meetingID}/agenda/${this.props.agendumID}/notes`;

        // Create the new note
        axios.post(url, { 
            authenticity_token: Utils.getAuthenticityToken(), 
            agendum_note: prop 
        }).then(response => {
            this.props.handleNewNote(response.data);
        });
    }

    /*
     * Handle the updating of an existing note's contents.
     */
    updateNote = (prop) => {
        var url = `/meetings/${this.props.meetingID}`
            + `/agenda/${this.props.agendumID}`
            + `/notes/${this.state.note.id}`;

        axios.patch(url, {
            authenticity_token: Utils.getAuthenticityToken(),
            agendum_note: prop
        }).then(response => {
            this.setState({ note: response.data });
        });
    }

    render() {
        var isExisting = this.state.note.id;

        var noteClass = 'collection-item' + 
            (!isExisting ? ' grey-text' : '');

        return(
            <li className={noteClass}>
                <RIETextArea
                    change={isExisting ? this.updateNote : this.addNewNote}
                    value={isExisting ? this.state.note.content : 'Add a new note...'}
                    propName="content" />
            </li>
        );
    }
}
{'fraction_non_alphanumeric': 0.13312597200622084, 'fraction_numerical': 0.0, 'mean_word_length': 1.8791405550581917, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2268389', 'n_tokens_mistral': 975, 'n_tokens_neox': 948, 'n_words': 206}