2016-02-08 07:26:10 -05:00
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
2016-03-14 08:50:46 -04:00
import $ from 'jquery' ;
2016-03-23 04:06:08 +05:00
require ( 'perfect-scrollbar/jquery' ) ( $ ) ;
2016-03-14 08:50:46 -04:00
import React from 'react' ;
import ReactDOM from 'react-dom' ;
2016-06-22 10:30:01 -04:00
import { Router , browserHistory } from 'react-router/es6' ;
2016-08-30 18:56:02 -04:00
import PDFJS from 'pdfjs-dist' ;
2016-05-26 09:46:18 -04:00
import * as GlobalActions from 'actions/global_actions.jsx' ;
2016-06-22 10:30:01 -04:00
import * as Websockets from 'actions/websocket_actions.jsx' ;
import BrowserStore from 'stores/browser_store.jsx' ;
2016-03-24 12:05:50 -04:00
import * as I18n from 'i18n/i18n.jsx' ;
2016-02-08 07:26:10 -05:00
2016-06-22 10:30:01 -04:00
// Import our styles
import 'bootstrap-colorpicker/dist/css/bootstrap-colorpicker.css' ;
import 'google-fonts/google-fonts.css' ;
import 'sass/styles.scss' ;
2016-08-29 09:50:00 -04:00
import 'katex/dist/katex.min.css' ;
2016-06-22 10:30:01 -04:00
// Import the root of our routing tree
import rRoot from 'routes/route_root.jsx' ;
2016-04-01 11:48:19 -04:00
2016-08-30 18:56:02 -04:00
PDFJS . disableWorker = true ;
2016-02-08 07:26:10 -05:00
// This is for anything that needs to be done for ALL react components.
// This runs before we start to render anything.
function preRenderSetup ( callwhendone ) {
2016-04-21 22:37:01 -07:00
window . onerror = ( msg , url , line , column , stack ) => {
var l = { } ;
l . level = 'ERROR' ;
l . message = 'msg: ' + msg + ' row: ' + line + ' col: ' + column + ' stack: ' + stack + ' url: ' + url ;
$ . ajax ( {
2016-05-24 14:31:30 -07:00
url : '/api/v3/general/log_client' ,
2016-04-21 22:37:01 -07:00
dataType : 'json' ,
contentType : 'application/json' ,
type : 'POST' ,
data : JSON . stringify ( l )
} ) ;
if ( window . mm _config && window . mm _config . EnableDeveloper === 'true' ) {
2016-04-25 05:38:41 -07:00
window . ErrorStore . storeLastError ( { type : 'developer' , message : 'DEVELOPER MODE: A javascript error has occured. Please use the javascript console to capture and report the error (row: ' + line + ' col: ' + column + ').' } ) ;
2016-04-21 22:37:01 -07:00
window . ErrorStore . emitChange ( ) ;
2016-02-08 07:26:10 -05:00
}
2016-04-21 22:37:01 -07:00
} ;
2016-02-08 07:26:10 -05:00
2016-04-21 22:37:01 -07:00
var d1 = $ . Deferred ( ) ; //eslint-disable-line new-cap
2016-02-08 07:26:10 -05:00
2016-04-21 22:37:01 -07:00
GlobalActions . emitInitialLoad (
( ) => {
d1 . resolve ( ) ;
2016-02-08 07:26:10 -05:00
}
) ;
2016-05-16 19:09:37 -04:00
// Make sure the websockets close and reset version
2016-03-14 08:50:46 -04:00
$ ( window ) . on ( 'beforeunload' ,
( ) => {
2016-05-16 19:09:37 -04:00
BrowserStore . setLastServerVersion ( '' ) ;
2016-03-23 10:20:52 -04:00
Websockets . close ( ) ;
2016-03-14 08:50:46 -04:00
}
) ;
2016-03-21 12:33:44 -04:00
function afterIntl ( ) {
2016-04-21 22:37:01 -07:00
$ . when ( d1 ) . done ( ( ) => {
2016-06-02 16:47:26 -03:00
I18n . doAddLocaleData ( ) ;
2016-04-21 22:37:01 -07:00
callwhendone ( ) ;
} ) ;
2016-03-21 12:33:44 -04:00
}
if ( global . Intl ) {
afterIntl ( ) ;
} else {
2016-03-25 22:36:55 -04:00
I18n . safariFix ( afterIntl ) ;
2016-03-21 12:33:44 -04:00
}
2016-02-08 07:26:10 -05:00
}
function renderRootComponent ( ) {
ReactDOM . render ( (
< Router
history = { browserHistory }
2016-06-22 10:30:01 -04:00
routes = { rRoot }
/ >
2016-02-08 07:26:10 -05:00
) ,
document . getElementById ( 'root' ) ) ;
}
global . window . setup _root = ( ) => {
// Do the pre-render setup and call renderRootComponent when done
preRenderSetup ( renderRootComponent ) ;
} ;