<commit_before>import React from "react/addons";
import "./Author.css";
import $ from "jquery";
import Tabs from "../Tabs/Tabs.es6";

//http://community.citizenedu.tw/users/kris/activity
import Author from "./Author.json";
//http://community.citizenedu.tw/users/kris/activity/posts
import AuthorPost from "./AuthorPost.json";

export default React.createClass({
  displayName: "Author",

  getInitialState(){
      return {
         scroll: false,
         focusTab: 'article',
         showFullBio: false
      }
  },

  _onToggle(choice, event){
      this.setState({
          focusTab: choice
      });
  },

  _onShowFullBio(){
      this.setState({
          showFullBio: true
      });

  },

  componentDidMount() {
    var ref = this.refs.AuthorWidget;
    if(!ref) return;

    var rect = ref.getDOMNode().getBoundingClientRect();
    var bottom = rect.bottom;
    var scroll = this.state.scroll;

    var _this = this;
    var cb = function(value){
        //console.log("callback:"+value);
        _this.setState({
            scroll: value
        });
    };

    $(window).scroll(function(event){
        // console.log("s"+$(this).scrollTop());
        // console.log(bottom);
        // console.log($(this).scrollTop() < bottom );
        // console.log(scroll);

        if( $(this).scrollTop() > bottom ){
            cb(true);
        }
        if( $(this).scrollTop() < bottom ){

            cb(false);
        }
    });
  },
  render() {
      //console.log(Author.user.bio_excerpt);
      //console.log(Author.user.bio_raw);
      //
      var result = "";
      if(this.props.type === "section"){
          result = (
              <div className="Author">
                 <a href="/author/1">
                 <div dangerouslySetInnerHTML={{__html: Author.user.bio_excerpt}}></div>
                 <div className="Author-gotoBio">作者個人頁面</div>
                 </a>
              </div>
          )

      }else if(this.props.type === "widget"){
          var classSet = React.addons.classSet;
          var classes = classSet({
              "Author-widget" : true,
              "Author-fixedWidget": this.state.scroll
          });

          result = (
              <div className={classes}
                   ref="AuthorWidget">
                  <img className="Author-widgetAvatar"
                       src="http://okapi.books.com.tw/uploads/article/article10144_3.png" />
                  <div className="Author-widgetInfo">
                      <a className="Author-widgetLink"
                         href="/author/1">朱家安</a>・<a className="Author-widgetLink">沃草烙哲學</a>
                      <span className="Author-tagsSection">
                          <span className="Author-tags">／</span>
                          <a className="Author-tagLink">哲學</a>
                          <span className="Author-tags">・</span>
                          <a className="Author-tagLink">藝術</a>
                      </span>
                  </div>
              </div>
          )

      }else if(this.props.type === "page"){
          /* ================================
           *   Tabs
           * ================================ */
          var tabs = [{id:'article', title: '文章'},
                      {id:'bio', title: '簡介'}];

          var postItems = AuthorPost.map((item, key)=>{
              return(<commit_msg>add subjects and tags rendering<commit_after>import Debug from "debug"
import React from "react/addons";
import "./Author.css";
import $ from "jquery";
import Tabs from "../Tabs/Tabs.es6";

var debug = Debug('component:Author')

//http://community.citizenedu.tw/users/kris/activity
import Author from "./Author.json";
//http://community.citizenedu.tw/users/kris/activity/posts
import AuthorPost from "./AuthorPost.json";

export default React.createClass({
  _extract(name){
    var all = {}
    this.props.collections[name].forEach(function (x) {
      all[x.title] = true
    })
    return this.props.collection.filter((c) => all[c])
  },

  renderColumn(){
    var column = this._extract('columns')[0]
    debug('render column %s', column)
    return (
      <a className='Author-widgetLink' href={'/columns/' + column}>{column}</a>
      )
  },
  renderSubjects(){
    debug('render subjects %s', this._extract('subjects'))
    var subjects = this._extract('subjects').map((s) =>
      <a className="Author-tagLink" href={'/subjects/' + s} key={s}>{s}</a>
    )
    return subjects
  },
  renderTags(){
    debug('render tags %s', this._extract('tags'))
    return this._extract('tags').map((t) =>
      <a className="Author-tagLink" href={'/tags/' + t} key={t}>{t}</a>
    )
  },
  _join(items, sep){
    var result = []
    items.forEach(function (x, i) {
      result.push(x)
      if (i < items.length - 1) {
        result.push(sep)
      }
    })
    return result
  },

  displayName: "Author",

  getInitialState(){
      return {
         scroll: false,
         focusTab: 'article',
         showFullBio: false
      }
  },

  _onToggle(choice, event){
      this.setState({
          focusTab: choice
      });
  },

  _onShowFullBio(){
      this.setState({
          showFullBio: true
      });

  },

  componentDidMount() {
    var ref = this.refs.AuthorWidget;
    if(!ref) return;

    var rect = ref.getDOMNode().getBoundingClientRect();
    var bottom = rect.bottom;
    var scroll = this.state.scroll;

    var _this = this;
    var cb = function(value){
        _this.setState({
            scroll: value
        });
    };

    $(window).scroll(function(event){

        if( $(this).scrollTop() > bottom ){
            cb(true);
        }
        if( $(this).scrollTop() < bottom ){

            cb(false);
        }
    });
  },
  render() {
      var result = "";
      if(this.props.type === "section"){
          result = (
              <div className="Author">
                 <a href="/author/1">
                 <div dangerouslySetInnerHTML={{__html: Author.user.bio_excerpt}}></div>
                 <div className="Author-gotoBio">作者個人頁面</div>
                 </a>
              </div>
          )

      }else if(this.props.type === "widget"){
    // XXX metalsmith reverses arrays in meta
    this.props.collection.reverse()
          var classSet = React.addons.classSet;
          var classes = classSet({
              "Author-widget" : true,
              "Author-fixedWidget": this.state.scroll
          });

          result = (
              <div className={classes}
                   ref="AuthorWidget">
                  <img className="Author-widgetAvatar"
                       src="http://okapi.books.com.tw/uploads/article/article10144_3.png" />
                  <div className="Author-widgetInfo">
                      <a className="Author-widgetLink"
                         href="/author/1">{this.props.author}</a>・<a className="Author-widgetLink">{this.renderColumn()}</a>
                      <span className="Author-tagsSection">
                          <span className="Author-tags">／</span>
                          {this._join(this.renderSubjects().concat(this.renderTags()), <span className="Author-tags">・</span>)}
                      </span>
                  </div>
              </div>
          )

      }else if(this.props.type === "page"){
          /* ================================
           *   Tabs
           * ================================ */
          var tabs = [{id:'article', title: '文章'},
                      {id:'bio', title: '簡介'}];

          var postItems = AuthorPost.map((item, key)=>{
              return(
{'fraction_non_alphanumeric': 0.1723182477899459, 'fraction_numerical': 0.002638870563398865, 'mean_word_length': 1.8022181146025877, 'pattern_counts': {'":': 2, '<': 63, '<?xml version=': 0, '>': 66, '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': '3495308', 'n_tokens_mistral': 2253, 'n_tokens_neox': 2170, 'n_words': 389}