{"size": 2155, "ext": "js", "max_stars_repo_path": "app/component/StoryItem.js", "max_stars_repo_name": "riston/hackernews-extension", "max_stars_repo_stars_event_min_datetime": "2015-08-09T07:40:39.000Z", "max_stars_repo_stars_event_max_datetime": "2015-09-18T12:54:43.000Z", "max_issues_repo_path": "app/component/StoryItem.js", "max_issues_repo_name": "riston/hackernews-extension", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/component/StoryItem.js", "max_forks_repo_name": "riston/hackernews-extension", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 5, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 34.7580645161, "max_line_length": 134, "alphanum_fraction": 0.5016241299}

import "../style/item.less";

import React, {Component, PropTypes} from "react";
import moment from "moment";
import CN from "classnames";

import Badge from "./Badge";

export default class StoryItem extends Component {

    static propTypes = {
        id:          PropTypes.number.isRequired,
        type:        PropTypes.oneOf(["story", "comment", "job", "poll"]).isRequired,
        title:       PropTypes.string.isRequired,
        url:         PropTypes.string.isRequired,
        time:        PropTypes.number.isRequired,
        by:          PropTypes.string.isRequired,
        score:       PropTypes.number.isRequired,
        descendants: PropTypes.number.isRequired,
        deleted:     PropTypes.bool,
    }

    static defaultProps = {
        score: 0,
        title: "No news title",
        descendants: [],
        deleted: false,
    }

    render ()
    {
        let baseLink = `https://news.ycombinator.com/item?id=${this.props.id}`;
        let timeFromNow = moment(this.props.time * 1e3).fromNow();
        let classes = CN("hn-item", {
            deleted: Boolean(this.props.deleted)
        });

        return (
            <div className={classes}>
                <div className="text">
                    <Badge score={this.props.score} />
                    <span className="title">
                        <a href={this.props.url} target="_blank"
                            data-action="story-open"
                            data-item-id={this.props.id}>{this.props.title}</a>
                        <button className="comment-count"
                            data-action="comment-view"
                            data-item-id={this.props.id}>{`(${this.props.descendants})`}
                        </button>
                        <a href={baseLink} target="_blank" className="external-link"><i className="fa fa-fw fa-external-link"></i></a>
                    </span>
                </div>
                <div className="sub">
                    <span>&ndash; by {this.props.by}</span>
                    <span>&nbsp;{timeFromNow}</span>
                </div>
            </div>
        );
    }
}
