summaryrefslogtreecommitdiffstats
path: root/web/react/components/channel_loader.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'web/react/components/channel_loader.jsx')
-rw-r--r--web/react/components/channel_loader.jsx62
1 files changed, 62 insertions, 0 deletions
diff --git a/web/react/components/channel_loader.jsx b/web/react/components/channel_loader.jsx
new file mode 100644
index 000000000..5252f275c
--- /dev/null
+++ b/web/react/components/channel_loader.jsx
@@ -0,0 +1,62 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+/* This is a special React control with the sole purpose of making all the AsyncClient calls
+ to the server on page load. This is to prevent other React controls from spamming
+ AsyncClient with requests. */
+
+var AsyncClient = require('../utils/async_client.jsx');
+var SocketStore = require('../stores/socket_store.jsx');
+var Constants = require('../utils/constants.jsx');
+
+module.exports = React.createClass({
+ componentDidMount: function() {
+ /* Start initial aysnc loads */
+ AsyncClient.getMe();
+ AsyncClient.getPosts(true);
+ AsyncClient.getChannels(true, true);
+ AsyncClient.getChannelExtraInfo(true);
+ AsyncClient.findTeams();
+ AsyncClient.getStatuses();
+ /* End of async loads */
+
+
+ /* Start interval functions */
+ setInterval(function(){AsyncClient.getStatuses();}, 30000);
+ /* End interval functions */
+
+
+ /* Start device tracking setup */
+ var iOS = /(iPad|iPhone|iPod)/g.test( navigator.userAgent );
+ if (iOS) {
+ $("body").addClass("ios");
+ }
+ /* End device tracking setup */
+
+
+ /* Start window active tracking setup */
+ window.isActive = true;
+
+ $(window).focus(function() {
+ AsyncClient.updateLastViewedAt();
+ window.isActive = true;
+ });
+
+ $(window).blur(function() {
+ window.isActive = false;
+ });
+ /* End window active tracking setup */
+
+ /* Start global change listeners setup */
+ SocketStore.addChangeListener(this._onSocketChange);
+ /* End global change listeners setup */
+ },
+ _onSocketChange: function(msg) {
+ if (msg && msg.user_id) {
+ UserStore.setStatus(msg.user_id, "online");
+ }
+ },
+ render: function() {
+ return <div/>;
+ }
+});