Main.purs 1.48 KB
Newer Older
Abinaya Sudhir's avatar
Abinaya Sudhir committed
1 2 3 4 5
module Main where

import Prelude

import Data.Maybe (fromJust)
Sudhir Kumar's avatar
Sudhir Kumar committed
6 7 8
import Effect (Effect)
import Gargantext.Pages.Layout (dispatchAction)
import Gargantext.Pages.Layout.Specs (layoutSpec)
9
import Gargantext.Pages.Layout.States (initAppState)
10
import Gargantext.Router (routeHandler, routing)
Abinaya Sudhir's avatar
Abinaya Sudhir committed
11 12 13
import Partial.Unsafe (unsafePartial)
import React as R
import ReactDOM as RDOM
14
import Record.Unsafe (unsafeSet)
Sudhir Kumar's avatar
Sudhir Kumar committed
15
import Routing.Hash (getHash, matches, setHash)
Abinaya Sudhir's avatar
Abinaya Sudhir committed
16
import Thermite as T
Sudhir Kumar's avatar
Sudhir Kumar committed
17 18 19
import Web.DOM.ParentNode (QuerySelector(..), querySelector)
import Web.HTML (window)
import Web.HTML.Window (document)
20 21
import Web.HTML.HTMLDocument (toParentNode)

22 23
setUnsafeComponentWillMount :: forall s. Effect Unit -> Record s -> Record (unsafeComponentWillMount :: Effect Unit | s)
setUnsafeComponentWillMount = unsafeSet "unsafeComponentWillMount"
Abinaya Sudhir's avatar
Abinaya Sudhir committed
24

25
main :: Effect Unit
26
main = do
27
 case T.createReactSpec layoutSpec initAppState of
Abinaya Sudhir's avatar
Abinaya Sudhir committed
28
    { spec, dispatcher } -> void $ do
29 30
      let setRouting this = void $ do
            matches routing (routeHandler (dispatchAction (dispatcher this)))
31
          spec' this = setUnsafeComponentWillMount (setRouting this) <$> (spec this)
Sudhir Kumar's avatar
Sudhir Kumar committed
32
      document <- window >>= document
33
      container <- unsafePartial (fromJust  <$> querySelector (QuerySelector "#app") (toParentNode document))
34 35 36 37 38 39
      h <- getHash
      case h of
        "" -> setHash "/"
        _ -> do
          setHash "/"
          setHash h
40
      let e = R.unsafeCreateElement (R.component "GargantextMain" spec') {} []
41
      RDOM.render e container