<commit_before>import React, { Component } from 'react';
import Gallery from './Gallery.react';
import InfiniteScroll from './InfiniteScroll.react';
import AlbumApi from '../api/albumApi';
import map from 'lodash/collection/map';

// Container component inspired by:
// https://medium.com/@learnreact/container-components-c0e67432e005#.rkxj8u626
class GalleryContainer extends Component {
  constructor(props) {
    super(props);
    this.state = {
      assets: [],
      loadedPageCount: 0,
      hasMorePages: false,
    };
  }

  componentWillMount() {
    this.loadMore(); // Load the first batch
  }

  processApiResponse(response) {
    // TODO
  }

  updatePageCount(response) {
    const newState = {
      loadedPageCount: this.state.loadedPageCount + 1,
      hasMorePages: !!response.pagination.next_page,
    };
    this.setState(newState);
  }

  handleApiError(error) {
    // TODO
  }

  loadMore() {
    AlbumApi.fetchAssets('aACiujyl', { page: this.state.loadedPageCount + 1 })
      .then(this.processApiResponse)
      .then(this.updatePageCount)
      .catch(this.handleApiError);
  }

  render() {
    const { assets } = this.state;<commit_msg>Remap original asset object to a custom one.<commit_after>import React, { Component } from 'react';
import Gallery from './Gallery.react';
import InfiniteScroll from './InfiniteScroll.react';
import AlbumApi from '../api/albumApi';
import map from 'lodash/collection/map';

// Container component inspired by:
// https://medium.com/@learnreact/container-components-c0e67432e005#.rkxj8u626
class GalleryContainer extends Component {
  constructor(props) {
    super(props);
    this.state = {
      assets: [],
      loadedPageCount: 0,
      hasMorePages: false,
    };
  }

  componentWillMount() {
    this.loadMore(); // Load the first batch
  }

  processApiResponse(response) {
    const newAssets = map(response.data, (asset) => {
      return {
        author: {
          username: asset.user.username,
          avatarUrl: asset.user.avatar,
        },
        service: asset.source.service,
        importUrl: asset.source.import_url,
        url: asset.url,
        caption: asset.caption,
        shortcut: asset.shortcut,
      };
    });

    const assets = this.state.assets
      .slice()
      .concat(newAssets);

    this.setState({ assets });
  }

  updatePageCount(response) {
    const newState = {
      loadedPageCount: this.state.loadedPageCount + 1,
      hasMorePages: !!response.pagination.next_page,
    };
    this.setState(newState);
  }

  handleApiError(error) {
    // TODO
  }

  loadMore() {
    const opts = {
      page: this.state.loadedPageCount + 1,
    };
    AlbumApi.fetchAssets('aACiujyl', opts)
      .then((r) => this.processApiResponse(r))
      .then((r) => this.updatePageCount(r))
      .catch((r) => this.handleApiError(r));
  }

  render() {
    const { assets } = this.state;
{'fraction_non_alphanumeric': 0.13264248704663212, 'fraction_numerical': 0.011053540587219343, 'mean_word_length': 2.8768406961178044, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '6527599', 'n_tokens_mistral': 931, 'n_tokens_neox': 889, 'n_words': 176}