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