<commit_before>import React from "react";
import Input from "material-ui/Input";
import InputLabel from "material-ui/Input/InputLabel";
import Button from "material-ui/Button";
import FormControl from "material-ui/Form/FormControl";
import TextField from "material-ui/TextField";
import CircularProgress from "material-ui/Progress";
import Autorenew from "material-ui-icons/Autorenew";
import Grid from "material-ui/Grid";
import List, { ListItem, ListItemText } from "material-ui/List";

import PropTypes from "prop-types";
import { withStyles, createStyleSheet } from "material-ui/styles";

import steem from "steem";

const styleSheet = createStyleSheet("TextFields", theme => ({
  container: {
    display: "flex",
    flexWrap: "wrap"
  },
  button: {
    marginTop: "17px"
  },
  progress: {
    // margin: `0 ${theme.spacing.unit * 2}px`,
  },
  grid: {
    direction: "row",
    justifyContent: "center",
    alignItems: "center",
    height: "100px"
  },
  textField: {
    // marginLeft: theme.spacing.unit,
    // marginRight: theme.spacing.unit,
    // width: 200
  }
}));

// recursive return all the comments
function getData(root, items) {
  steem.api.getContentReplies(root.author, root.permlink).then(results => {
    results.map(el => {
      items.push({
        author: el.author,
        body: el.body,
        created: el.created,
        permlink: el.permlink
      });
      if (el.children > 0) {
        getData(el, items);
      } else {
        // leaf
      }
    });
  });
}

// return root {author, permLink}
function getRoot(steemUrl) {
  const tokens = steemUrl.split("/");
  const permLink = tokens.pop(); // last piece
  const user = tokens.pop().slice(1); // remove @
  return {
    author: user,
    permlink: permLink
  };
}

class SelectUrlStep extends React.Component {
  state = {
    steemitUrl: null,
      // "https://steemit.com/italiano/@luigi-tecnologo/announcement-steemwinner-the-easiest-way-to-pick-up-your-contest-or-giveaway-winners",
    loading: false,
    totalComments: null,
    shuffledUsers: []
  };

  constructor(props) {
    super(props);
    this.handleClick = this.handleClick.bind(this);
  }

  handleClick(ev) {
    const { steemitUrl, loading } = this.state;
    this.setState({ loading: true });
    console.log("ev ", steemitUrl);

    const rootPost = getRoot(steemitUrl);

    steem.api.getContent(rootPost.author, rootPost.permlink).then(post => {
      const voters = post.active_votes.map(item => item.voter);
      //console.log(voters)

      const comments = [];
      getData(rootPost, comments);<commit_msg>fix null url<commit_after>import React from "react";
import Input from "material-ui/Input";
import InputLabel from "material-ui/Input/InputLabel";
import Button from "material-ui/Button";
import FormControl from "material-ui/Form/FormControl";
import TextField from "material-ui/TextField";
import CircularProgress from "material-ui/Progress";
import Autorenew from "material-ui-icons/Autorenew";
import Grid from "material-ui/Grid";
import List, { ListItem, ListItemText } from "material-ui/List";

import PropTypes from "prop-types";
import { withStyles, createStyleSheet } from "material-ui/styles";

import steem from "steem";

const styleSheet = createStyleSheet("TextFields", theme => ({
  container: {
    display: "flex",
    flexWrap: "wrap"
  },
  button: {
    marginTop: "17px"
  },
  progress: {
    // margin: `0 ${theme.spacing.unit * 2}px`,
  },
  grid: {
    direction: "row",
    justifyContent: "center",
    alignItems: "center",
    height: "100px"
  },
  textField: {
    // marginLeft: theme.spacing.unit,
    // marginRight: theme.spacing.unit,
    // width: 200
  }
}));

// recursive return all the comments
function getData(root, items) {
  steem.api.getContentReplies(root.author, root.permlink).then(results => {
    results.map(el => {
      items.push({
        author: el.author,
        body: el.body,
        created: el.created,
        permlink: el.permlink
      });
      if (el.children > 0) {
        getData(el, items);
      } else {
        // leaf
      }
    });
  });
}

// return root {author, permLink}
function getRoot(steemUrl) {
  const tokens = steemUrl.split("/");
  const permLink = tokens.pop(); // last piece
  const user = tokens.pop().slice(1); // remove @
  return {
    author: user,
    permlink: permLink
  };
}

class SelectUrlStep extends React.Component {
  state = {
    steemitUrl: '',
      // "https://steemit.com/italiano/@luigi-tecnologo/announcement-steemwinner-the-easiest-way-to-pick-up-your-contest-or-giveaway-winners",
    loading: false,
    totalComments: null,
    shuffledUsers: []
  };

  constructor(props) {
    super(props);
    this.handleClick = this.handleClick.bind(this);
  }

  handleClick(ev) {
    const { steemitUrl, loading } = this.state;
    this.setState({ loading: true });
    console.log("ev ", steemitUrl);

    const rootPost = getRoot(steemitUrl);

    steem.api.getContent(rootPost.author, rootPost.permlink).then(post => {
      const voters = post.active_votes.map(item => item.voter);
      //console.log(voters)

      const comments = [];
      getData(rootPost, comments);
{'fraction_non_alphanumeric': 0.14548268523892435, 'fraction_numerical': 0.0046430644225188625, 'mean_word_length': 3.1526104417670684, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 2, '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': '2859057', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1677, 'n_words': 358}