-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
89 lines (77 loc) · 2.82 KB
/
index.js
File metadata and controls
89 lines (77 loc) · 2.82 KB
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
/*
* Load external dependencies
*/
var React = require("react");
var Dispatcher = require("flux").Dispatcher;
/*
* Global initialization
*/
// Load navbar React components
var UserSessionStore = require("./js/stores/UserSessionStore.react");
var UserSessionActionCreator = require('./js/actions/UserSessionActions.react');
var NavBarUserInfo = require('./js/components/NavBarUserInfo.react');
// Initialize navbar dispatcher and session store
var dispatcher = new Dispatcher();
var userSessionStore = new UserSessionStore();
var sessionStoreRegistration = dispatcher.register(function(action){
userSessionStore.emit(action.actionType,action);
});
// Set up session API
require('./js/apis/UserSessionApi').setUp(userSessionStore);
// Set up session action creator
UserSessionActionCreator.setUp(dispatcher);
/*
* Initialize the top navbar
*/
React.render(<NavBarUserInfo userSessionStore={userSessionStore}><li className="navbar-nav-button"><a href="/">Home</a></li></NavBarUserInfo>, $("#navbar-container")[0]);
UserSessionActionCreator.initialize();
/*
* Global functions
*/
window.skillicious = window.skillicious || {};
window.skillicious.redirectToSignin = function(){
setTimeout(function(){
window.location.assign("/");
},200);
};
window.skillicious.redirectToProfile = function(){
window.location.assign("/profile");
};
/*
* Page-specific initialization functions
*/
// Registration page
window.skillicious.initializeRegistrationForm = function(domElement){
var RegistrationForm = require('./js/components/RegistrationForm.react');
// If the user is already authenticated, redirect to the profile page.
if (userSessionStore.principal)
window.skillicious.redirectToProfile();
else
React.render(<RegistrationForm />, domElement);
};
// User profile page
var Router = require('react-router');
window.skillicious.initializeProfile = function(domElement){
// Set up action creator
var UserProfileActionCreator = require('./js/actions/UserProfileActions.react');
UserProfileActionCreator.setUp(dispatcher);
// Set up store
var UserProfileStore = require('./js/stores/UserProfileStore.react');
var userProfileStore = new UserProfileStore();
// Register store with the dispatcher
dispatcher.register(function(action){
dispatcher.waitFor([sessionStoreRegistration]);
userProfileStore.emit(action.actionType,action);
});
// Set up profile API
require('./js/apis/UserProfileApi').setUp(userSessionStore);
var UserProfile = require('./js/components/UserProfile.react');
UserProfile.setUserProfileStore(userProfileStore);
UserProfile.setUserSessionStore(userSessionStore);
UserProfileActionCreator.initialize().catch(function(error){
alert("Error loading profile");
});
Router.run(UserProfile.createRoutes(), Router.HashLocation, function(Root){
React.render(<Root />, domElement);
});
};