Version.purs 1.84 KB
Newer Older
1 2 3
module Gargantext.Version where

import Data.Maybe (Maybe(..))
4 5 6
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff, launchAff_)
import Effect.Class (liftEffect)
7 8 9 10
import Prelude
import Reactix as R
import Reactix.DOM.HTML as H

11 12 13
import Gargantext.Config.REST as REST
import Gargantext.Ends (toUrl)
import Gargantext.Sessions (Session(..))
14
import Gargantext.Sessions as Sessions
15

16
thisModule :: String
17
thisModule = "Gargantext.Version"
18 19 20 21 22 23 24

type Version = String

foreign import version :: Version

getBackendVersion :: Session -> Aff Version
getBackendVersion (Session { backend }) = REST.get Nothing (toUrl backend "version")
25 26 27 28 29 30 31 32 33 34 35


type VersionProps =
  (
    session :: Sessions.Session
  )

versionView :: Record VersionProps -> R.Element
versionView props = R.createElement versionCpt props []

versionCpt :: R.Component VersionProps
36
versionCpt = R.hooksComponentWithModule thisModule "version" cpt
37 38 39 40 41 42 43 44 45 46
  where
    cpt { session } _ = do
      (versionBack /\ setVer) <- R.useState' "No Backend Version"

      R.useEffect' $ do
        launchAff_ $ do
          v <- getBackendVersion session
          liftEffect $ setVer $ const v

      pure $ case version == versionBack of
47
        true  -> H.a { className: "fa fa-check-circle-o"
48
                     , textDecoration: "none"
49 50 51 52 53 54
                     , title: "Versions match: frontend ("
                            <> version
                            <> "), backend ("
                            <> versionBack
                            <> ")"
                      } []
55
        false -> H.a { className: "fa fa-exclamation-triangle"
56
                     , textDecoration: "none"
57 58 59 60 61
                     , title: "Versions mismatch: frontend ("
                            <> version
                            <> "), backend ("
                            <> versionBack
                            <> ")"
62
                     } []
63