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

import DOM.Simple (document, querySelector)
arturo's avatar
arturo committed
6
import Data.Maybe (Maybe(..), maybe)
arturo's avatar
arturo committed
7 8 9 10
import Gargantext.Components.Bootstrap as B
import Gargantext.Components.Bootstrap.Types (Variant(..))
import Gargantext.Components.Frame.Types (Base, Hyperdata(..), FrameId)
import Gargantext.Components.Node (NodePoly(..))
11
import Gargantext.Prelude
arturo's avatar
arturo committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
import Gargantext.Types (NodeType(..))
import Gargantext.Utils.Reactix as R2
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
  , nodeType :: NodeType
  )

layout :: R2.Leaf Props
layout = R2.leaf layoutCpt
layoutCpt :: R.Component Props
layoutCpt = here.component "main" cpt where
30
  cpt { frame: NodePoly { hyperdata: Hyperdata { base, frame_id } }
arturo's avatar
arturo committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
      , nodeType
      } _ = case nodeType of

    -- Visio Node
    NodeFrameVisio ->

      case WURL.fromAbsolute base of

        Nothing  ->

          pure $

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

49
        Just _url ->
arturo's avatar
arturo committed
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

          -- 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
78 79 80 81 82 83 84
      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
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

      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%"
          }
          []
        ]

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

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
-- 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" } [ ]
arturo's avatar
arturo committed
132 133 134 135

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

hframeUrl :: NodeType -> Base -> FrameId -> String
arturo's avatar
arturo committed
136
hframeUrl NodeFrameNotebook base frame_id = base <> "/" <> frame_id  -- Temp fix : frame_id is currently the whole url created
137
hframeUrl Calc  base frame_id    = base <> "/" <> frame_id
arturo's avatar
arturo committed
138 139
hframeUrl NodeFrameVisio base frame_id    = base <> "/" <> frame_id
hframeUrl _ base frame_id                 = base <> "/" <> frame_id <> "?view" -- "?both"