Commit ecab7506 authored by James Laver's avatar James Laver

Refactor Main

parent 4c51907c
module Main where
import Prelude
import Prelude (Unit, ($))
import Data.Maybe (fromJust)
import Data.Maybe (Maybe(..))
import Data.Nullable (toMaybe)
import DOM.Simple.Document (document)
import DOM.Simple.Console (log)
import Effect (Effect)
import Gargantext.Pages.Layout (dispatchAction)
import Gargantext.Pages.Layout.Specs (layoutSpec)
import Gargantext.Pages.Layout.States (initAppState)
import Gargantext.Router (routing)
import Partial.Unsafe (unsafePartial)
import React as R
import ReactDOM as RDOM
import Record.Unsafe (unsafeSet)
import Routing.Hash (getHash, matches, setHash)
import Thermite as T
import Web.DOM.ParentNode (QuerySelector(..), querySelector)
import Web.HTML (window)
import Web.HTML.Window (document)
import Web.HTML.HTMLDocument (toParentNode)
setUnsafeComponentWillMount :: forall s. Effect Unit -> Record s -> Record (unsafeComponentWillMount :: Effect Unit | s)
setUnsafeComponentWillMount = unsafeSet "unsafeComponentWillMount"
import FFI.Simple ((...))
import Reactix as R
import Gargantext.Components.Layout (layout)
main :: Effect Unit
main = do
state <- initAppState
case T.createReactSpec layoutSpec (const state) of
{ spec, dispatcher } -> void $ do
let setRouting this = void $ do
matches routing (dispatchAction (dispatcher this))
spec' this = setUnsafeComponentWillMount (setRouting this) <$> (spec this)
document <- window >>= document
container <- unsafePartial (fromJust <$> querySelector (QuerySelector "#app") (toParentNode document))
h <- getHash
case h of
"" -> setHash "/"
_ -> do
setHash "/"
setHash h
let e = R.unsafeCreateElement (R.component "GargantextMain" spec') {} []
RDOM.render e container
main = paint $ toMaybe $ document ... "getElementById" $ [ "app" ]
paint Nothing = log "[main] Container not found"
paint (Just c) = R.render (layout {}) c
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment