-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.jsx
executable file
·76 lines (51 loc) · 1.61 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
/** @jsx React.DOM */
'use strict'
window.init = function() {
var ROOT = 'https://the-eye-of-sauron.appspot.com/_ah/api';
gapi.client.load('sauron', 'v1', function() {
var React = require('react');
var page = require('page');
var Header = require('./views/Header');
var HeaderAfterLogin = require('./views/HeaderAfterLogin');
var ErrorPage = require('./components/ErrorPage');
var Feed = require('./views/Feed');
var Router = React.createClass({
getInitialState: function () {
return { component: <ErrorPage />};
},
componentDidMount: function () {
var _this = this;
this.props.routes.forEach(function (route) {
var url = route[0];
var Component = route[1];
page(url, function (ctx) {
React.render(<Header />, document.getElementById('header'))
_this.setState({ component: <Component params={ctx.params} /> });
});
});
page.start();
},
render: function () {
var element = <div id="component"> {this.state.component} </div>
Renderer.unmount(document.getElementById('component'));
return element;
}
});
/**
* Ref : https://github.com/facebook/react/issues/4498
* This helps us in unmounting the component
**/
var Renderer = {
unmount: function(node) {
if( node != null) {
React.unmountComponentAtNode(node);
}
}
}
var routes = [
['', Feed],
['/feed', Feed]
];
React.render(<Router routes={routes} />, document.getElementById('right-side-bar'));
}, ROOT);
};