Layout.purs 4.31 KB
Newer Older
arturo's avatar
arturo committed
1 2 3 4 5 6 7 8
module Gargantext.Components.Frame.Layout
  ( layout
  ) where

import Gargantext.Prelude

import DOM.Simple (document, querySelector)
import DOM.Simple as DOM
arturo's avatar
arturo committed
9
import Data.Maybe (Maybe(..), maybe)
arturo's avatar
arturo committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
import Data.Nullable (Nullable, null, toMaybe)
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (Variant(..))
import Gargantext.Components.FolderView as FV
import Gargantext.Components.Frame.Types (Base, Hyperdata(..), FrameId)
import Gargantext.Components.Node (NodePoly(..))
import Gargantext.Types (NodeType(..))
import Gargantext.Utils.JitsiMeet as JM
import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Toestand as T2
import Reactix as R
import Reactix.DOM.HTML as H
import Web.URL as WURL

here :: R2.Here
here = R2.here "Gargantext.Components.Frame.Layout"

type Props =
  ( frame    :: NodePoly Hyperdata
  , reload   :: T2.ReloadS
  , nodeId   :: Int
  , nodeType :: NodeType
  )

layout :: R2.Leaf Props
layout = R2.leaf layoutCpt

layoutCpt :: R.Component Props
layoutCpt = here.component "main" cpt where
  cpt { frame: NodePoly { hyperdata: h@(Hyperdata { base, frame_id }) }
      , nodeId
      , nodeType
      , reload
      } _ = case nodeType of

    -- Visio Node
    NodeFrameVisio ->

      case WURL.fromAbsolute base of

        Nothing  ->

          pure $

            B.caveat
            { variant: Warning }
            [
              H.text $ "Wrong base url: " <> base
            ]

        Just url ->

          -- pure $ nodeFrameVisio' { frame_id, reload, url }
          pure $

            H.div
            {}
            [
              B.h1_ "Visio Room"
            ,
              H.a
              { className : "fa fa-video-camera fa-5x"
              , href : hframeUrl nodeType base frame_id
              , target: "_blank"
              }
              []
            ,
              B.p_ "Click on the Camera logo to access to your room"
            ,
              B.p_ "This a unique room dedicated to your team"
            ,
              B.p_ "Works with Chromium/Chrome only for now."
            ]

    -- Other Frame Nodes
    _ -> do

      -- @XXX: reset "main-page__main-route" wrapper margin
      --       see Gargantext.Components.Router) (@TODO?)
arturo's avatar
arturo committed
89 90 91 92 93 94 95
      R.useLayoutEffect1 [] do
        let mEl = querySelector document ".main-page__main-route"
        -- Mount
        mEl >>= maybe R.nothing (flip R2.addClass ["p-0"])
        -- Unmount
        pure $
          mEl >>= maybe R.nothing (flip R2.removeClass ["p-0"])
arturo's avatar
arturo committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147

      pure $

        H.div
        { className: "frame-layout"
        , rows: "100%,*"
        }
        [
          -- H.script { src: "https://visio.gargantext.org/external_api.js"} [],
          H.iframe
          { src: hframeUrl nodeType base frame_id
          , width: "100%"
          , height: "100%"
          }
          []
        ]

--------------------------------------------------------------

type NodeFrameVisioProps =
  ( frame_id  :: String
  , reload    :: T2.ReloadS
  , url       :: WURL.URL
  )

nodeFrameVisio :: R2.Leaf NodeFrameVisioProps
nodeFrameVisio = R2.leaf nodeFrameVisioCpt

nodeFrameVisioCpt :: R.Component NodeFrameVisioProps
nodeFrameVisioCpt = here.component "nodeFrameVisio" cpt where
  cpt { frame_id
      , url
      } _  = do
    ref <- R.useRef (null :: Nullable DOM.Element)

    R.useEffect' $ do
      here.log2 "[nodeFrameVisio] ref" $ R.readRef ref
      here.log2 "[nodeFrameVisio] JM.api" JM._api
      case toMaybe (R.readRef ref) of
        Nothing -> pure unit
        Just r  -> do
          api <- JM.jitsiMeetAPI (WURL.host url) { parentNode: r
                                                  , roomName: frame_id
                                                  , width: "100%"
                                                  , height: "100%" }
          here.log2 "[nodeFrameVisio] api" api

    pure $ H.div { ref, className: "jitsi-iframe" } [ ]

--------------------------------------------------------------

hframeUrl :: NodeType -> Base -> FrameId -> String
arturo's avatar
arturo committed
148 149 150 151
hframeUrl NodeFrameNotebook base frame_id = base <> "/" <> frame_id  -- Temp fix : frame_id is currently the whole url created
hframeUrl NodeFrameCalc  base frame_id    = base <> "/" <> frame_id
hframeUrl NodeFrameVisio base frame_id    = base <> "/" <> frame_id
hframeUrl _ base frame_id                 = base <> "/" <> frame_id <> "?view" -- "?both"