<commit_before>import React from 'react';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import Menu from './menu.jsx';

const Home = () => {
  if (localStorage.getItem('accessToken')) {
    return (<MuiThemeProvider muiTheme={getMuiTheme()}>
    <div>
      <Menu />
      Welcome to pixlr
    </div>
  </MuiThemeProvider>)
} else {
  window.location.href = '/';
}
  };

// LoginForm.propTypes = {<commit_msg>[Feature 126837405] Add helper methods for getting & presenting images.<commit_after>import React from 'react';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import Menu from './menu.jsx';
import SideBar from './sideBar.jsx';
import request from 'superagent';

const generateFolders = (imageList) => (
  // return a list of unique folders
  Array.from(new Set(imageList.map((image) => {
    if (image.folder_name === '') {
      return 'untitled';
    }
    return image.folder_name;
  })))
);

const organizeImages = (imageList, folderList) => {
  return folderList.map((folder) => (
    {[folder]: imageList.filter((image) => {
      if (image.folder_name === folder) {
        return image
      } else if(image.folder_name === '' && folder === 'untitled') {
        return image
      }
    })}
  ))
}

const fetchImage = () => {
  // returns a Promise object.
  return new Promise((resolve, reject) => {
    request
    .get('/api/v1/images/')
    .set('Authorization', `Bearer facebook ${localStorage.getItem('accessToken')}`)
    .end((error, result) => {
      if (!error) {
        resolve(result.body);
      } else {
        reject(error);
      }
    });
  });
};


const Home = () => {
  let images = []
  if (localStorage.getItem('accessToken')) {
    fetchImage().then((response) => {
      images = response;
      console.log(organizeImages(response, generateFolders(response)));
    });
    return (
    <MuiThemeProvider muiTheme={getMuiTheme()}>
      {/*<div className="row start-xs">
        <Menu />
        Welcome to pixlr
      </div>*/}
      <div>
        <Menu />
        <div className="row start-xs">
          <div className="col-xs-3">
            <SideBar images={images}/>
          </div>
        </div>
      </div>
  </MuiThemeProvider>)
} else {
  window.location.href = '/';
}
  };

// LoginForm.propTypes = {
{'fraction_non_alphanumeric': 0.16459884201819686, 'fraction_numerical': 0.004549214226633582, 'mean_word_length': 2.8519108280254777, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 32, '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': '4014324', 'n_tokens_mistral': 771, 'n_tokens_neox': 758, 'n_words': 162}