/*
 This file is a part of libertysoil.org website
 Copyright (C) 2015  Loki Education (Social Enterprise)

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Affero General Public License for more details.

 You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
import React from 'react';
import { connect } from 'react-redux';
import _ from 'lodash';

import {API_HOST} from '../config';
import ApiClient from '../api/client'
import CreatePost from '../components/create-post'
import Header from '../components/header';
import Footer from '../components/footer';
import River from '../components/river_of_posts';
import Sidebar from '../components/sidebar';
import SidebarAlt from '../components/sidebarAlt';
import { getStore } from '../store';
import { addError } from '../actions';
import { createPost, likePost, unlikePost, favPost, unfavPost, loadSchools } from '../triggers';
import { defaultSelector } from '../selectors';


class Index extends React.Component {

  // TODO(voidxnull): EnterHandler doesn't call the fetchData function for the component.
  componentDidMount() {
    Index.fetchData(this.props);
  }

  static async fetchData(props) {
    if (props.current_user_id === null) {
      return;
    }

    try {
      if (getStore().getState().get('schools').isEmpty()) {
        await loadSchools();
      }
    } catch (e) {
      getStore().dispatch(addError(e.message));
    }

  }

  render() {
    let triggers = {likePost, unlikePost, favPost, unfavPost};

    return (
      <div>
        <Header is_logged_in={this.props.is_logged_in} current_user={this.props.current_user} />
        <div className="page__container">
          <div className="page__body">
            <Sidebar current_user={this.props.current_user} />
            <div className="page__content">
              <CreatePost triggers={{createPost}} schools={this.props.schools} />
              <River river={this.props.river} posts={this.props.posts} users={this.props.users} current_user={this.props.current_user} triggers={triggers}/>
              {/*<Followed/> */}
              {/*<Tags/>*/}
            </div>
            <SidebarAlt />
          </div>
        </div>
        <Footer/>
      </div>
    )
  }
}

export default connect(defaultSelector)(Index);

@@ -837,16 +837,66 @@
 lodash';
+%0Aimport %7B replacePath %7D from 'redux-simple-router'
 %0A%0Aimport
@@ -1384,16 +1384,25 @@
 favPost,
+%0A        
  loadSch
@@ -1405,16 +1405,31 @@
 dSchools
+, loadPostRiver
  %7D from 
@@ -1499,21 +1499,20 @@
 %0A%0Aclass 
-Index
+List
  extends
@@ -1534,364 +1534,155 @@
 t %7B%0A
-%0A
   
-// TODO(voidxnull): EnterHandler doesn't call the fetchData function for the component.%0A  componentDidMount() %7B%0A    Index.fetchData(this.props);%0A  %7D%0A%0A  static async fetchData(props) %7B%0A    if (props.current_user_id === null) %7B%0A      return;%0A    %7D%0A%0A    try %7B%0A      if (getStore().getState().get('schools').isEmpty()) %7B%0A        await loadSchools();%0A      %7D
+static displayName = 'List';%0A%0A  static async fetchData(params, state, client) %7B%0A    try %7B%0A      await loadSchools();%0A      await loadPostRiver();
 %0A   
@@ -1750,17 +1750,16 @@
 ;%0A    %7D%0A
-%0A
   %7D%0A%0A  r
@@ -2608,12 +2608,11 @@
 or)(
-Index
+List
 );%0A

Refactor List page