Commit 90f5ec44 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[CodeEditor] add file functionality

parent df5c9252
module Gargantext.Components.Nodes.Corpus where module Gargantext.Components.Nodes.Corpus where
import Data.Argonaut (class DecodeJson, encodeJson) import Data.Argonaut (class DecodeJson, encodeJson)
import Data.Array (head) import Data.Array as A
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Data.Tuple (fst)
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2) import DOM.Simple.Console (log2)
import Effect.Aff (Aff, throwError) import Effect.Aff (Aff, throwError)
import Effect.Exception (error) import Effect.Exception (error)
...@@ -47,10 +49,28 @@ corpusLayoutViewCpt :: R.Component ViewProps ...@@ -47,10 +49,28 @@ corpusLayoutViewCpt :: R.Component ViewProps
corpusLayoutViewCpt = R.hooksComponent "G.C.N.C.corpusLayoutView" cpt corpusLayoutViewCpt = R.hooksComponent "G.C.N.C.corpusLayoutView" cpt
where where
cpt {corpus: (NodePoly {hyperdata: CorpusHyperdata {fields}}), nodeId, session} _ = do cpt {corpus: (NodePoly {hyperdata: CorpusHyperdata {fields}}), nodeId, session} _ = do
pure $ H.div {} fieldsS <- R.useState' fields
(corpusFieldCodeEditor {nodeId, session} <$> fields)
pure $ H.div {} [
H.div {} (corpusFieldCodeEditor {nodeId, session} <$> (fst fieldsS))
, H.div { className: "row" } [
H.div { className: "btn btn-default"
, on: { click: onClick fieldsS }
} [
H.span { className: "glyphicon glyphicon-plus" } [ ]
]
]
]
--H.iframe { src: gargMd , width: "100%", height: "100%", style: {"border-style": "none"}} [] --H.iframe { src: gargMd , width: "100%", height: "100%", style: {"border-style": "none"}} []
--gargMd = "https://hackmd.iscpif.fr/g9Aah4iwQtCayIzsKQjA0Q#" --gargMd = "https://hackmd.iscpif.fr/g9Aah4iwQtCayIzsKQjA0Q#"
onClick (_ /\ setFieldsS) _ = do
setFieldsS $ \fieldsS -> A.snoc fieldsS $ CorpusField {
name: "New file"
, typ: Markdown {
tag: "MarkdownField"
, text: "# New file"
}
}
corpusFieldCodeEditor :: Record LoadProps -> CorpusField CorpusFieldType -> R.Element corpusFieldCodeEditor :: Record LoadProps -> CorpusField CorpusFieldType -> R.Element
corpusFieldCodeEditor p (CorpusField {name, typ}) = corpusFieldCodeEditor p (CorpusField {name, typ}) =
...@@ -60,6 +80,7 @@ corpusFieldCodeEditor p (CorpusField {name, typ}) = ...@@ -60,6 +80,7 @@ corpusFieldCodeEditor p (CorpusField {name, typ}) =
corpusFieldCodeEditor' typ corpusFieldCodeEditor' typ
] ]
] ]
corpusFieldCodeEditor' :: CorpusFieldType -> R.Element corpusFieldCodeEditor' :: CorpusFieldType -> R.Element
corpusFieldCodeEditor' (Markdown {text}) = corpusFieldCodeEditor' (Markdown {text}) =
CE.codeEditor {code: text, defaultCodeType: CE.Markdown, onChange} CE.codeEditor {code: text, defaultCodeType: CE.Markdown, onChange}
...@@ -87,7 +108,7 @@ loadCorpus {nodeId, session} = do ...@@ -87,7 +108,7 @@ loadCorpus {nodeId, session} = do
(NodePoly {parentId: corpusId} :: NodePoly {}) <- get session nodePolyRoute (NodePoly {parentId: corpusId} :: NodePoly {}) <- get session nodePolyRoute
corpusNode <- get session $ corpusNodeRoute corpusId "" corpusNode <- get session $ corpusNodeRoute corpusId ""
defaultListIds <- (get session $ defaultListIdsRoute corpusId) :: forall a. DecodeJson a => AffTableResult (NodePoly a) defaultListIds <- (get session $ defaultListIdsRoute corpusId) :: forall a. DecodeJson a => AffTableResult (NodePoly a)
case (head defaultListIds.docs :: Maybe (NodePoly HyperdataList)) of case (A.head defaultListIds.docs :: Maybe (NodePoly HyperdataList)) of
Just (NodePoly { id: defaultListId }) -> Just (NodePoly { id: defaultListId }) ->
pure {corpusId, corpusNode, defaultListId} pure {corpusId, corpusNode, defaultListId}
Nothing -> Nothing ->
......
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