import 'bootstrap/dist/css/bootstrap.min.css' ; import 'bootstrap/dist/js/bootstrap.min.js' ; import 'jquery' ; import 'popper.js' ; import 'jquery-toast-plugin/dist/jquery.toast.min.css' ; import 'jquery-toast-plugin/dist/jquery.toast.min.js' ; import '@src/client/vendors/web-picture-viewer.js' ; import '@src/client/vendors/arrive-footer.js' ; import '@src/client/vendors/float-fixed.js' ; import '@src/client/vendors/load-demand' ; import 'highlight.js/styles/github.css' ; import 'github-markdown-css/github-markdown.css' ; import React from 'react' ; import ReactDOM from 'react-dom' ; import { BrowserRouter } from 'react-router-dom' ; import { Provider } from 'react-redux' ; import { matchPath } from 'react-router' ; import ReactGA from 'react-ga' ; import './service-worker' ; import configureStore from '@app/redux' ; import createRouter from '@app/router' ; import * as socket from './socket' ; import * as browser from '@app/common/browser' ; import { GA , analysisScript } from '@config' ; import { debug } from '@config/feature.config' ; import { getUserInfo } from '@app/redux/reducers/user' ; import { initUnlockToken } from '@app/redux/actions/unlock-token' ; import { requestNotificationPermission } from '@app/redux/actions/website' ; import { initHasRead } from '@app/redux/actions/has-read-posts' ; import theme from './theme' ; import initData from '@app/init-data' ; ( async function ( ) { const store = configureStore ( window . __initState__ ) ; let userinfo = null ; let isAppShell = window . inAppShell || false ; if ( isAppShell ) { await initData ( store ) ; await new Promise ( ( resolve , reject ) => { $ . ajax ( { url : '/sign/check' , type : 'post' , success : ( res ) => { if ( res && res . signIn && ! res . error ) { store . dispatch ( { type : 'SET_USER' , userinfo : res . userInfo } ) ; if ( res . accessToken ) { store . dispatch ( { type : 'ADD_ACCESS_TOKEN' , access_token : res . accessToken } ) ; } } userinfo = getUserInfo ( store . getState ( ) ) ; resolve ( ) ; } , error : ( err ) => { resolve ( ) ; } } ) ; } ) ; } else { userinfo = getUserInfo ( store . getState ( ) ) ; } initUnlockToken ( ) ( store . dispatch , store . getState ) ; requestNotificationPermission ( ) ( store . dispatch , store . getState ) ; let enterEvent = ( userinfo ? ) : void => { } ; if ( GA ) { let gaOptions = { } ; if ( userinfo ) { gaOptions . userId = userinfo . _id ; } ReactGA . initialize ( GA , { debug , gaOptions } ) ; enterEvent = ( userinfo ) => { ReactGA . pageview ( window . location . pathname + window . location . search ) ; } ; } const router = createRouter ( { user : userinfo , enterEvent } ) ; const Page = router . dom ; socket . connect ( store ) ; let _route = null ; router . list . some ( ( route ) => { let match = matchPath ( window . location . pathname , route ) ; if ( match && match . path ) { _route = route ; return true ; } } ) ; await _route . body . preload ( ) ; if ( isAppShell ) $ ( '#app' ) [ 0 ] . innerHTML = '' ; ReactDOM . hydrate ( < Provider store = { store } > < BrowserRouter > < Page /></BrowserRouter > < /Provider>, $('#app')[0]); if ( process . env . NODE_ENV === 'development' && module . hot ) module . hot . accept ( ) ; $ ( 'body' ) . append ( `<div style="display:none">${ analysisScript }</div>` ) ; if ( browser . isSafari ( ) ) { document . addEventListener ( 'touchmove' , function ( e ) { e . preventDefault ( ) ; } ) ; } initHasRead ( ) ( store . dispatch , store . getState ) ; theme ( userinfo ) ; } ( ) ) ;