<commit_before>import React, { Component, PropTypes } from 'react';
import { ipcRenderer } from 'electron';
import { open } from 'openurl';

import CategoryItemInput from './CategoryItemInput';
import CategoryItem from './CategoryItem';

import EntryCategory from './EntryCategory';

class HatenaForm extends Component {
  constructor(props) {
    super(props);
    this.state = ({
      title: '',
      hatenaUsername: window.localStorage.getItem('hatenaUsername'),
      hatenaBlogId: window.localStorage.getItem('hatenaBlogId'),
      hatenaApikey: window.localStorage.getItem('hatenaApikey'),
      draftStatus: false,
      openAfterPost: false,
    });
  }

  componentDidMount() {
    ipcRenderer.on('Error', (event, err) => {
      console.error(err);
      alert('エラー\n' + err);
    });
    ipcRenderer.on('Response', (event, res) => {
      console.log(res);
      alert('はてなブログに投稿しました｡\n' + res);
      if (this.state.openAfterPost) {
        open(res);
      }
    });
  }

  onClickedPublic() {
    this.setState({ draftStatus: false });
  }

  onClickedDraft() {
    this.setState({ draftStatus: true });
  }

  handleTitleChange(e) {
    this.setState({ title: e.target.value });
  }

  handleHatenaUsernameChange(e) {
    this.setState({ hatenaUsername: e.target.value });
  }

  handleHatenaBlogIdChange(e) {
    this.setState({ hatenaBlogId: e.target.value });
  }

  handleHatenaApikeyChange(e) {
    this.setState({ hatenaApikey: e.target.value });
  }

  handleSave(text) {
    if (text.length !== 0) {
      this.props.actions.addCategoryItem(text);
    }
  }

  handleClickOpenAfterPost() {
    if (this.state.openAfterPost) {
      this.setState({ openAfterPost: false });
    } else {
      this.setState({ openAfterPost: true });
    }
  }

  postHatena() {
    ipcRenderer.send('hatenaPostWsse', this.state.title, this.state.content, this.state.hatenaUsername, this.state.hatenaBlogId, this.state.hatenaApikey, this.state.category, this.state.draftStatus);
  }

  render() {
    let btnPublicClass = 'btn btn-default';
    if (!this.state.draftStatus) btnPublicClass += ' active';

    let btnDraftClass = 'btn btn-default';
    if (this.state.draftStatus) btnDraftClass += ' active';

    const { title, hatenaUsername, hatenaBlogId, hatenaApikey, openAfterPost } = this.state;
    const { categoryItems, actions, entryCategory } = this.props;<commit_msg>add new feature<commit_after>import React, { Component, PropTypes } from 'react';
import { ipcRenderer } from 'electron';
import { open } from 'openurl';

import CategoryItemInput from './CategoryItemInput';
import CategoryItem from './CategoryItem';

import EntryCategory from './EntryCategory';

class HatenaForm extends Component {
  constructor(props) {
    super(props);
    this.state = ({
      title: '',
      hatenaUsername: window.localStorage.getItem('hatenaUsername'),
      hatenaBlogId: window.localStorage.getItem('hatenaBlogId'),
      hatenaApikey: window.localStorage.getItem('hatenaApikey'),
      draftStatus: false,
      openAfterPost: false,
    });
  }

  componentDidMount() {
    ipcRenderer.on('Error', (event, err) => {
      console.error(err);
      alert('エラー\n' + err);
    });
    ipcRenderer.on('Response', (event, res) => {
      console.log(res);
      alert('はてなブログに投稿しました｡\n' + res);
      if (this.state.openAfterPost) {
        open(res);
      }
    });
  }

  onClickedPublic() {
    this.setState({ draftStatus: false });
  }

  onClickedDraft() {
    this.setState({ draftStatus: true });
  }

  handleTitleChange(e) {
    this.setState({ title: e.target.value });
  }

  handleHatenaUsernameChange(e) {
    this.setState({ hatenaUsername: e.target.value });
  }

  handleHatenaBlogIdChange(e) {
    this.setState({ hatenaBlogId: e.target.value });
  }

  handleHatenaApikeyChange(e) {
    this.setState({ hatenaApikey: e.target.value });
  }

  handleSave(text) {
    if (text.length !== 0) {
      this.props.actions.addCategoryItem(text);
    }
  }

  handleClickOpenAfterPost() {
    if (this.state.openAfterPost) {
      this.setState({ openAfterPost: false });
    } else {
      this.setState({ openAfterPost: true });
    }
  }

  postHatena() {
    let categoryArray = [];
    for (let i = 0; i < this.props.entryCategory.length; i++) {
      console.log(this.props.entryCategory[i].text);
      categoryArray.push(this.props.entryCategory[i].text);
    }

    ipcRenderer.send('hatenaPostWsse', this.state.title, this.state.content, this.state.hatenaUsername, this.state.hatenaBlogId, this.state.hatenaApikey, categoryArray, this.state.draftStatus);
  }

  render() {
    let btnPublicClass = 'btn btn-default';
    if (!this.state.draftStatus) btnPublicClass += ' active';

    let btnDraftClass = 'btn btn-default';
    if (this.state.draftStatus) btnDraftClass += ' active';

    const { title, hatenaUsername, hatenaBlogId, hatenaApikey, openAfterPost } = this.state;
    const { categoryItems, actions, entryCategory } = this.props;
{'fraction_non_alphanumeric': 0.1444935691318328, 'fraction_numerical': 0.0006028938906752412, 'mean_word_length': 3.44375, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, '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': '7363074', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1614, 'n_words': 286}