<commit_before>import React from 'react';
import HomePageSection from './generic-section';
import { Link } from 'react-router';
import ProjectCard from '../../partials/project-card';
import apiClient from 'panoptes-client/lib/api-client';

const RecentProjectsSection = React.createClass({
  propTypes: {
    onClose: React.PropTypes.func,
  },

  contextTypes: {
    user: React.PropTypes.object.isRequired,
  },

  getInitialState() {
    return {
      loading: false,
      error: null,
      projects: [],
      avatars: {},
    };
  },

  componentDidMount() {
    this.fetchProjects(this.context.user);
  },

  componentWillReceiveProps(nextProps, nextContext) {
    if (nextContext.user !== this.context.user) {
      this.fetchProjects(nextContext.user);
    }
  },

  fetchProjects(user) {
    this.setState({
      loading: true,
      error: null,
      avatars: {},
    });

    user.get('project_preferences', {
      sort: '-updated_at',
    })
    .then((preferences) => {
      const activePreferences = preferences.filter((projectPreference) => {
        return projectPreference.activity_count > 0;
      });
      const recentPreferences = activePreferences.filter(Boolean).slice(0, 5);
      return Promise.all(recentPreferences.map((preference) => {
        // A user might have preferences for a project that no longer exists.
        return apiClient.type('projects').get({id: preference.links.project, cards: true}).then(function(project) {
          return project[0];
        }).catch(() => {
          return null;
        });
      })).then((projects) => {
        return projects.filter(Boolean);
      });
    })
    .then((projects) => {
      this.setState({
        projects,
      });
    })
    .catch((error) => {
      this.setState({
        error: error,
        projects: [],
      });
    })
    .then(() => {
      this.setState({
        loading: false,
      });
    });
  },

  render() {
    return (
      <HomePageSection
        title="Recent projects"
        loading={this.state.loading}
        error={this.state.error}
        onClose={this.props.onClose}
      >
        <div className="home-page-section__sub-header">
          <Link to={`/users/${this.context.user.login}/stats`} className="outlined-button">See all</Link>
        </div>

        {this.state.projects.length === 0 && (
          <div className="home-page-section__header-label">
            <p> You have no recent projects. </p>
          </div>
        )}

        <div className="project-card-list">
          {this.state.projects.map((project) => {
            console.log(project);
            return <ProjectCard key={project.id} project={project} />;
          })}
        </div>
      </HomePageSection>
    );
  },
});

export default RecentProjectsSection;<commit_msg>get all the project cards in one got<commit_after>import React from 'react';
import HomePageSection from './generic-section';
import { Link } from 'react-router';
import ProjectCard from '../../partials/project-card';
import apiClient from 'panoptes-client/lib/api-client';

const RecentProjectsSection = React.createClass({
  propTypes: {
    onClose: React.PropTypes.func,
  },

  contextTypes: {
    user: React.PropTypes.object.isRequired,
  },

  getInitialState() {
    return {
      loading: false,
      error: null,
      projects: [],
      avatars: {},
    };
  },

  componentDidMount() {
    this.fetchProjects(this.context.user);
  },

  componentWillReceiveProps(nextProps, nextContext) {
    if (nextContext.user !== this.context.user) {
      this.fetchProjects(nextContext.user);
    }
  },

  fetchProjects(user) {
    this.setState({
      loading: true,
      error: null,
      avatars: {},
    });

    user.get('project_preferences', {
      sort: '-updated_at',
    })
    .then((preferences) => {
      const activePreferences = preferences.filter((projectPreference) => {
        return projectPreference.activity_count > 0;
      });
      const recentPreferences = activePreferences.filter(Boolean).slice(0, 5);
      const project_ids = recentPreferences.map((preference) => {
        return preference.links.project
      });
      return apiClient.type('projects').get({id: project_ids, cards: true}).catch(() => {
        return null;
      });
    })
    .then((projects) => {
      this.setState({
        projects,
      });
    })
    .catch((error) => {
      this.setState({
        error: error,
        projects: [],
      });
    })
    .then(() => {
      this.setState({
        loading: false,
      });
    });
  },

  render() {
    return (
      <HomePageSection
        title="Recent projects"
        loading={this.state.loading}
        error={this.state.error}
        onClose={this.props.onClose}
      >
        <div className="home-page-section__sub-header">
          <Link to={`/users/${this.context.user.login}/stats`} className="outlined-button">See all</Link>
        </div>

        {this.state.projects.length === 0 && (
          <div className="home-page-section__header-label">
            <p> You have no recent projects. </p>
          </div>
        )}

        <div className="project-card-list">
          {this.state.projects.map((project) => {
            return <ProjectCard key={project.id} project={project} />;
          })}
        </div>
      </HomePageSection>
    );
  },
});

export default RecentProjectsSection;
{'fraction_non_alphanumeric': 0.15301963690255652, 'fraction_numerical': 0.0016672841793256763, 'mean_word_length': 2.3388991960420533, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 48, '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': '3006434', 'n_tokens_mistral': 1595, 'n_tokens_neox': 1568, 'n_words': 280}