{"size": 1624, "ext": "js", "max_stars_repo_path": "ServerlessLibraryAPI/ClientApp/src/components/Contribute/ContributionsList.js", "max_stars_repo_name": "stefanushinardi/ServerlessLibrary", "max_stars_repo_stars_event_min_datetime": "2018-09-22T02:46:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-06T02:19:02.000Z", "max_issues_repo_path": "ServerlessLibraryAPI/ClientApp/src/components/Contribute/ContributionsList.js", "max_issues_repo_name": "stefanushinardi/ServerlessLibrary", "max_issues_repo_issues_event_min_datetime": "2018-09-21T22:27:59.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T11:09:57.000Z", "max_forks_repo_path": "ServerlessLibraryAPI/ClientApp/src/components/Contribute/ContributionsList.js", "max_forks_repo_name": "stefanushinardi/ServerlessLibrary", "max_forks_repo_forks_event_min_datetime": "2018-09-25T19:57:57.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-05T02:09:00.000Z"}
{"max_stars_count": 80, "max_issues_count": 87, "max_forks_count": 21, "avg_line_length": 27.0666666667, "max_line_length": 112, "alphanum_fraction": 0.6231527094}
import React, { Component } from "react";
import { connect } from "react-redux";
import { Label } from "office-ui-fabric-react";
import ItemList from "../../components/ItemList/ItemList";

class ContributionsList extends Component {
  filteredSamples() {
    let { loggedIn, user, samples } = this.props;
    let { userName } = user;
    if (!loggedIn || !userName) {
      return {};
    }

    let filter = new RegExp(userName, "i");
    samples = samples.filter(
      el =>
        el.repository.replace("https://github.com/", "").match(filter) || // this match should be against author
        (el.author && el.author.match(filter))
    );

    return samples;
  }

  render() {
    const headerLabelStyles = {
      root: {
        fontSize: "12px",
        fontWeight: "bold",
        paddingTop: "0px",
        paddingBottom: "6px"
      }
    };
    const filteredSamples = this.filteredSamples();
    return (
      <div className="contribution-list-container">
        <Label styles={headerLabelStyles}>My samples</Label>
        {filteredSamples.length > 0 ? (
          <ItemList filteredSamples={filteredSamples} disableHover={true} />
        ) : (
          <div className="empty-contribution-list-container">
            <i>You currently do not have any samples</i>
          </div>
        )}
      </div>
    );
  }
}

function mapStateToProps(state) {
  return {
    samples: state.samples,
    loggedIn: state.authentication.loggedIn,
    user: state.authentication.user
  };
}

const ContributionsListContainer = connect(mapStateToProps)(ContributionsList);

export default ContributionsListContainer;
