forked from FreeFeed/freefeed-react-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.jsx
120 lines (103 loc) · 5.62 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import 'styles/common/common.scss';
import 'styles/helvetica/app.scss';
import 'index.jade';
require.context('assets/fonts', true, /fontawesome.*/i);
import React from 'react';
import ReactDOM from 'react-dom';
import {Router, Route, IndexRoute, browserHistory} from 'react-router';
import {Provider} from 'react-redux';
import {syncHistoryWithStore} from 'react-router-redux';
import Autotrack from 'autotrack';
import configureStore from './redux/configure-store';
import * as ActionCreators from './redux/action-creators';
import Layout from './components/layout';
import Home from './components/home';
import Discussions from './components/discussions';
import About from './components/about';
import Dev from './components/dev';
import NotFound from './components/not-found';
import Signin from './components/signin';
import Signup from './components/signup';
import RestorePassword from './components/restore-password';
import ResetPassword from './components/reset-password';
import Settings from './components/settings';
import SinglePost from './components/single-post';
import User from './components/user';
import Subscribers from './components/subscribers';
import Subscriptions from './components/subscriptions';
import GroupSettings from './components/group-settings';
import GroupCreate from './components/group-create';
import Groups from './components/groups';
import SearchFeed from './components/search-feed';
import Friends from './components/friends';
import ManageSubscribers from './components/manage-subscribers';
import Bookmarklet from './components/bookmarklet';
const store = configureStore();
//request main info for user
if (store.getState().authenticated) {
store.dispatch(ActionCreators.whoAmI());
store.dispatch(ActionCreators.managedGroups());
} else {
// just commented for develop sign up form
store.dispatch(ActionCreators.unauthenticated());
}
import {bindRouteActions} from './redux/route-actions';
const boundRouteActions = bindRouteActions(store.dispatch);
const history = syncHistoryWithStore(browserHistory, store);
const manageSubscribersActions = next => {
const username = next.params.userName;
store.dispatch(ActionCreators.getUserInfo(username));
store.dispatch(ActionCreators.subscribers(username));
};
const friendsActions = next => {
const username = store.getState().user.username;
store.dispatch(ActionCreators.subscribers(username));
store.dispatch(ActionCreators.subscriptions(username));
store.dispatch(ActionCreators.blockedByMe(username));
};
// needed to display mutual friends
const subscribersSubscriptionsActions = next => {
const username = next.params.userName;
store.dispatch(ActionCreators.subscribers(username));
store.dispatch(ActionCreators.subscriptions(username));
};
const enterStaticPage = title => () => {
store.dispatch(ActionCreators.staticPage(title));
};
history.listen(_ => scrollTo(0, 0));
const generateRouteHooks = callback => ({
onEnter: callback,
onChange: (_, next) => callback(next),
});
ReactDOM.render(
<Provider store={store}>
<Router history={history}>
<Route name='bookmarklet' path='/bookmarklet' component={Bookmarklet}/>
<Route path='/' component={Layout}>
<IndexRoute name='home' component={Home} {...generateRouteHooks(boundRouteActions('home'))}/>
<Route path='about' component={About} onEnter={enterStaticPage('About')}/>
<Route path='dev' component={Dev} onEnter={enterStaticPage('Developers')}/>
<Route path='signin' component={Signin} onEnter={enterStaticPage('Sign in')}/>
<Route path='signup' component={Signup} onEnter={enterStaticPage('Sign up')}/>
<Route path='restore' component={RestorePassword}/>
<Route path='reset' component={ResetPassword}/>
<Route path='settings' component={Settings} onEnter={enterStaticPage('Settings')}/>
<Route name='groupSettings' path='/:userName/settings' component={GroupSettings} {...generateRouteHooks(boundRouteActions('getUserInfo'))}/>
<Route name='discussions' path='filter/discussions' component={Discussions} {...generateRouteHooks(boundRouteActions('discussions'))}/>
<Route name='direct' path='filter/direct' component={Discussions} {...generateRouteHooks(boundRouteActions('direct'))}/>
<Route name='search' path='search' component={SearchFeed} {...generateRouteHooks(boundRouteActions('search'))}/>
<Route name='groups' path='/groups' component={Groups} onEnter={enterStaticPage('Groups')}/>
<Route name='friends' path='/friends' component={Friends} onEnter={friendsActions}/>
<Route name='groupCreate' path='/groups/create' component={GroupCreate} onEnter={enterStaticPage('Create a group')}/>
<Route name='userFeed' path='/:userName' component={User} {...generateRouteHooks(boundRouteActions('userFeed'))}/>
<Route name='subscribers' path='/:userName/subscribers' component={Subscribers} onEnter={subscribersSubscriptionsActions}/>
<Route name='subscriptions' path='/:userName/subscriptions' component={Subscriptions} onEnter={subscribersSubscriptionsActions}/>
<Route name='manage-subscribers' path='/:userName/manage-subscribers' component={ManageSubscribers} onEnter={manageSubscribersActions}/>
<Route name='userComments' path='/:userName/comments' component={User} {...generateRouteHooks(boundRouteActions('userComments'))}/>
<Route name='userLikes' path='/:userName/likes' component={User} {...generateRouteHooks(boundRouteActions('userLikes'))}/>
<Route name='post' path='/:userName/:postId' component={SinglePost} {...generateRouteHooks(boundRouteActions('post'))}/>
</Route>
</Router>
</Provider>,
document.getElementById('app')
);