'use strict';

var React = require('react'),
    Router = require('react-router'),
    ReactBootstrap = require('react-bootstrap'),
    Reflux = require('reflux');


var SignIn = require('./membership/components/signin'),
    SignUp = require('./membership/components/signup'),
    Posts = require('./posts/components/posts'),
    Post = require('./posts/components/post'),
    Moderation = require('./posts/components/moderation'),
    Header = require('./shared/components/header'),
    Footer = require('./shared/components/footer'),
    actions = require('./actions'),
    userStore = require('./membership/stores/user');


var Grid = ReactBootstrap.Grid,
    Route = Router.Route;


var App = React.createClass({
    mixins: [Reflux.connect(userStore)],

    getInitialState: function() {
        return {user: null};
    },

    render: function() {
        return (
            <Grid>
                <Header user={this.state.user} />
                <Router.RouteHandler user={this.state.user} />
                <hr/>
                <Footer/>
            </Grid>
        );
    }
});

// <Redirect from="/" to="posts" />
var routes = (
    <Route handler={App}>
        <Route path="/" handler={Posts} />
        <Route name="posts" path="posts" handler={Posts} />
        <Route name="post" path="post/:slug" handler={Post} />
        <Route name="moderation" path="post/:slug/moderation"
               handler={Moderation} />
        <Route name="signin" path="signin" handler={SignIn} />
        <Route name="signup" path="signup" handler={SignUp} />
    </Route>
);

actions.searchPosts();
actions.loadDailyQuote();

Router.run(routes, Router.HistoryLocation, function(Root) {
    React.render(<Root/>, document.body);
});

@@ -813,12 +813,17 @@
 er: 
-null
+undefined
 %7D;%0A 
@@ -1580,16 +1580,42 @@
 te%3E%0A);%0A%0A
+actions.loadDailyQuote();%0A
 actions.
@@ -1633,38 +1633,28 @@
 ();%0Aactions.
-loadDailyQuote
+user
 ();%0A%0ARouter.

Set initial user state as undefined; call user action.