<commit_before>import React, { Component } from 'react';
import './index.css';
import './skeleton.min.css';
import './sweetalert2.min.css';

// Import npm modules
import * as firebase from 'firebase';
import * as Cookies from 'js-cookie';
import { default as swal } from 'sweetalert2'

// Setup
var config = {
   apiKey: "<KEY>",
   authDomain: "yourthoughts-1726a.firebaseapp.com",
   databaseURL: "https://yourthoughts-1726a.firebaseio.com",
   storageBucket: "yourthoughts-1726a.appspot.com"
 };
 firebase.initializeApp(config);

 var db = firebase.database();

// Functions
function makeid()
{
    var text = "";
    var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    for( var i=0; i < 10; i++ )
        text += possible.charAt(Math.floor(Math.random() * possible.length));

    return text;
}

if (Cookies.get('uid') === null || Cookies.get('uid') === undefined || Cookies.get('uid') == null || Cookies.get('uid') === '') {
  Cookies.set('uid', makeid());
  console.log(Cookies.get('uid'))
  db.ref('users/'+Cookies.get('uid')).set({
    name: ''
  })
}

 // Components
 class ThoughtView extends Component {

   constructor(props) {
     super(props);

     this.state = {
       thoughtId: '',
       thoughtPost: '',
       thoughtAuthor: ''
     }
   }

   handleChange() {

   }

   changeThought() {

   }

   componentWillMount () {
     console.log('DOM will load...')
   }

   render() {
     return (
       <div className="container">
         <div className="row">
           <div className="four columns"><p></p></div>
           <div className="four columns middlediv">
             <h3 className="title-thoughtview">{this.props.thoughtIdPiped}</h3>
             <h4 className="author">by {this.props.thoughtAuthorPiped}</h4>
           </div>
           <div className="four columns"><p></p></div>
         </div>
       </div>
     );
   }

   componentDidMount () {
     console.log('DOM has loaded at '+Date.now())
   }

 }

class MainView extends Component {

  constructor(props) {
    super(props);

    this.state = {
      vanityName: '',
      thoughtId: '',
      thoughtAuthor: '',
      thoughtPost: '',
      thoughtComments: {},
      rerender: false
    }
    this.handleChange = this.handleChange.bind(this);
    this.joinThought = this.joinThought.bind(this);
    this.createThought = this.createThought.bind(this);
    this.changeName = this.changeName.bind(this);
  }

  handleChange() {
    var inputIdData = document.getElementById('idInput').value;
    this.setState({thoughtId: inputIdData});

    var inputNameData = document.getElementById('idNameInput').value;
    this.setState({vanityName: inputNameData});
  }

  joinThought() {
    var self = this;
    var {thoughtId, rerender} = this.state;
    Cookies.set('thougtId', thoughtId)
    db.ref('thoughts/'+this.state.thoughtId).once('value', function(snapshot) {
      if (snapshot.hasChild('title')) {
        swal(
            'Success!',
            snapshot.key + ' does exist!',
            'success'
            )
        self.setState({
          rerender: true,
          thoughtAuthor: snapshot.val().author
        })
      } else {
        swal(
            'Awww!',
            snapshot.key + ' does not exist!',
            'error'
            )
      }
    })
  }

  createThought() {
    var self = this;
    var {thoughtId, rerender} = this.state;
    db.ref('thoughts/'+this.state.thoughtId).once('value', function(snapshot) {
      if (snapshot.hasChild('title')) {
        swal(
            'Aww!',
            snapshot.key + ' already exists!',
            'error'
            )
      } else {
        Cookies.set('thoughtId', thoughtId);
        db.ref('thoughts/'+thoughtId).set({
          title: '',
          titleCanBeChanged: true,
          postCanBeChange: true,
          post: '',
          author: Cookies.get('uid'),
          comments: {}
        });
        self.setState({
          rerender: true,
          thoughtAuthor: Cookies.get('uid')
        })
        swal(
            'Success!',
            thoughtId + ' has now been created!',
            'success'
            )
      }
    })<commit_msg>Adding functionality for vanity usernames by id<commit_after>import React, { Component } from 'react';
import './index.css';
import './skeleton.min.css';
import './sweetalert2.min.css';

// Import npm modules
import * as firebase from 'firebase';
import * as Cookies from 'js-cookie';
import { default as swal } from 'sweetalert2'

// Setup
var config = {
   apiKey: "<KEY>",
   authDomain: "yourthoughts-1726a.firebaseapp.com",
   databaseURL: "https://yourthoughts-1726a.firebaseio.com",
   storageBucket: "yourthoughts-1726a.appspot.com"
 };
 firebase.initializeApp(config);

 var db = firebase.database();

// Functions
function makeid()
{
    var text = "";
    var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    for( var i=0; i < 10; i++ )
        text += possible.charAt(Math.floor(Math.random() * possible.length));

    return text;
}

if (Cookies.get('uid') === null || Cookies.get('uid') === undefined || Cookies.get('uid') == null || Cookies.get('uid') === '') {
  Cookies.set('uid', makeid());
  console.log(Cookies.get('uid'))
  db.ref('users/'+Cookies.get('uid')).set({
    name: ''
  })
}

 // Components
 class ThoughtView extends Component {

   constructor(props) {
     super(props);

     this.state = {
       thoughtId: '',
       thoughtPost: '',
       thoughtAuthor: ''
     }
   }

   handleChange() {

   }

   changeThought() {

   }

   componentWillMount () {
     console.log('DOM will load...')
   }

   render() {
     return (
       <div className="container">
         <div className="row">
           <div className="four columns"><p></p></div>
           <div className="four columns middlediv">
             <h3 className="title-thoughtview">{this.props.thoughtIdPiped}</h3>
             <h4 className="author">by {this.props.thoughtAuthorPiped}</h4>
           </div>
           <div className="four columns"><p></p></div>
         </div>
       </div>
     );
   }

   componentDidMount () {
     console.log('DOM has loaded at '+Date.now())
   }

 }

class MainView extends Component {

  constructor(props) {
    super(props);

    this.state = {
      vanityName: '',
      thoughtId: '',
      thoughtAuthor: '',
      thoughtPost: '',
      thoughtComments: {},
      rerender: false
    }
    this.handleChange = this.handleChange.bind(this);
    this.joinThought = this.joinThought.bind(this);
    this.createThought = this.createThought.bind(this);
    this.changeName = this.changeName.bind(this);
  }

  handleChange() {
    var inputIdData = document.getElementById('idInput').value;
    this.setState({thoughtId: inputIdData});

    var inputNameData = document.getElementById('idNameInput').value;
    this.setState({vanityName: inputNameData});
  }

  joinThought() {
    var self = this;
    var {thoughtId, rerender} = this.state;
    Cookies.set('thougtId', thoughtId)
    db.ref('thoughts/'+this.state.thoughtId).once('value', function(snapshot) {
      if (snapshot.hasChild('title')) {
        swal(
            'Success!',
            snapshot.key + ' does exist!',
            'success'
            )
        self.setState({
          rerender: true,
          thoughtAuthor: snapshot.val().author
        })
      } else {
        swal(
            'Awww!',
            snapshot.key + ' does not exist!',
            'error'
            )
      }
    })
  }

  createThought() {
    var self = this;
    var {thoughtId, rerender} = this.state;
    db.ref('thoughts/'+this.state.thoughtId).once('value', function(snapshot) {
      if (snapshot.hasChild('title')) {
        swal(
            'Aww!',
            snapshot.key + ' already exists!',
            'error'
            )
      } else {
        Cookies.set('thoughtId', thoughtId);
        /*db.ref('users/'+Cookies.get('uid')).once('value', function(snapshot) {
          if (snapshot.hasChild('name')) {
            Cookies.set('vanityName', snapshot.val().name)
          }
        })*/
        db.ref('thoughts/'+thoughtId).set({
          title: '',
          titleCanBeChanged: true,
          postCanBeChange: true,
          post: '',
          author: Cookies.get('uid'),
          comments: {}
        });
        self.setState({
          rerender: true,
          thoughtAuthor: Cookies.get('uid')
        })
        swal(
            'Success!',
            thoughtId + ' has now been created!',
            'success'
            )
      }
    })
{'fraction_non_alphanumeric': 0.1570430733410943, 'fraction_numerical': 0.007217694994179278, 'mean_word_length': 2.252934494509655, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 41, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '782756', 'n_tokens_mistral': 2765, 'n_tokens_neox': 2645, 'n_words': 480}