Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
218 lines (194 loc) · 4.38 KB

File metadata and controls

218 lines (194 loc) · 4.38 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import React, { Component, cloneElement } from 'react';
import { connect } from 'react-redux';
import { browserHistory } from 'react-router';
import stream from 'getstream';
import config from 'config';
const Home = require('./routes/Home/Home').default;
import {
App as AppActions,
User as UserActions,
Photos as PhotoActions,
Header as HeaderActions,
Stream as StreamActions,
} from 'actions';
import { Header } from 'components';
/**
* AppHeader component
*/
@connect(state => ({
header: state.Header,
user: state.User,
}))
class AppHeader extends Component {
/**
* render
* @returns markup
*/
render() {
const { header, user, router } = this.props;
return (
<Header
left={header.left}
middle={header.middle}
right={header.right}
router={router}
userID={user.id}
/>
);
}
}
/**
* handleRouteChange
* @param dispatch
* @param route
* @param location
*/
function handleRouteChange(dispatch, route, location) {
if (route) {
if (route.getHeaderLeft) {
route.getHeaderLeft(location, (err, component) => {
dispatch(HeaderActions.left(component));
});
} else {
dispatch(HeaderActions.left(null));
}
if (route.getHeaderMiddle) {
route.getHeaderMiddle(location, (err, component) => {
dispatch(HeaderActions.middle(component));
});
} else {
dispatch(HeaderActions.middle(null));
}
if (route.getHeaderRight) {
route.getHeaderRight(location, (err, component) => {
dispatch(HeaderActions.right(component));
});
} else {
dispatch(HeaderActions.right(null));
}
}
}
/**
* App component
* Bootstraps application
*/
class App extends Component {
static contextTypes = {
router: React.PropTypes.object.isRequired,
};
componentWillMount() {
// instantiate a new client (client side)
this.client = stream.connect(
config.stream.key,
null,
config.stream.appId,
);
}
/**
* componentDidUpdate
* @param oldProps
* @returns {*}
*/
componentDidUpdate(oldProps) {
handleRouteChange(
this.props.dispatch,
this.props.routes[this.props.routes.length - 1],
this.props.location,
);
if (oldProps.user.id != this.props.user.id && !this.props.user.id) {
return browserHistory.push('/landing');
}
if (oldProps.user.id != this.props.user.id && this.props.user.id) {
this.connectToStream();
this.props.dispatch(AppActions.init());
}
}
/**
* componentDidMount
*/
componentDidMount() {
const { dispatch } = this.props;
FB.getLoginStatus(res => {
if (res.status !== 'connected') {
if (this.props.location.pathname != '/landing') {
browserHistory.replace('/landing');
}
this.props.dispatch(AppActions.initDone());
return;
}
dispatch(UserActions.fbLogin(res));
if (this.props.location.pathname == '/landing') {
browserHistory.replace('/');
}
});
}
connectToStream = () => {
// follow 'timeline_flat' feed
this.timeline = this.client.feed(
'timeline_flat',
this.props.user.id,
this.props.tokens.timelineFlat,
);
this.timeline
.subscribe(data => {
this.props.dispatch(StreamActions.timeline(data));
})
.then(
() => {
//console.log('Full (Timeline Flat): Connected to faye channel, waiting for realtime updates');
},
err => {
console.error(
'Full (Timeline Flat): Could not estabilsh faye connection',
err,
);
},
);
// follow 'notifications' feed
this.notification = this.client.feed(
'notification',
this.props.user.id,
this.props.tokens.notification,
);
this.notification
.subscribe(data => {
this.props.dispatch(StreamActions.event(data));
})
.then(
() => {
//console.log('Full (Notifications): Connected to faye channel, waiting for realtime updates');
},
err => {
console.error(
'Full (Notifications): Could not estabilsh faye connection',
err,
);
},
);
};
/**
* render
* @returns markup
*/
render() {
if (this.props.loading) return <div className="loader">Loading...</div>;
if (this.props.location.pathname == '/landing') {
return (
<div id="root">
{this.props.children || <Home />}
</div>
);
}
return (
<div id="root">
<AppHeader />
{this.props.children || <Home userID={this.props.user.id} />}
</div>
);
}
}
export default connect(state => ({
user: state.User,
loading: state.App.loading,
tokens: state.Tokens,
}))(App);
Morty Proxy This is a proxified and sanitized view of the page, visit original site.