Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
fda41cab
Commit
fda41cab
authored
Jan 24, 2020
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[CodeEditor] reload after saving to reset the component state
parent
1b4913c2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
8 deletions
+25
-8
Corpus.purs
src/Gargantext/Components/Nodes/Corpus.purs
+25
-8
No files found.
src/Gargantext/Components/Nodes/Corpus.purs
View file @
fda41cab
...
@@ -8,8 +8,9 @@ import Data.Maybe (Maybe(..))
...
@@ -8,8 +8,9 @@ import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..), fst)
import Data.Tuple (Tuple(..), fst)
import Data.Tuple.Nested ((/\))
import Data.Tuple.Nested ((/\))
import DOM.Simple.Console (log2)
import DOM.Simple.Console (log2)
import Effect.Aff (Aff, launchAff_, throwError)
import Effect (Effect)
import Effect (Effect)
import Effect.Aff (Aff, launchAff_, throwError)
import Effect.Class (liftEffect)
import Effect.Exception (error)
import Effect.Exception (error)
import Reactix as R
import Reactix as R
import Reactix.DOM.HTML as H
import Reactix.DOM.HTML as H
...
@@ -30,18 +31,23 @@ type Props = (
...
@@ -30,18 +31,23 @@ type Props = (
, session :: Session
, session :: Session
)
)
type Reload = R.State Int
corpusLayout :: Record Props -> R.Element
corpusLayout :: Record Props -> R.Element
corpusLayout props = R.createElement corpusLayoutCpt props []
corpusLayout props = R.createElement corpusLayoutCpt props []
corpusLayoutCpt :: R.Component Props
corpusLayoutCpt :: R.Component Props
corpusLayoutCpt = R.hooksComponent "G.C.N.C.corpusLayout" cpt
corpusLayoutCpt = R.hooksComponent "G.C.N.C.corpusLayout" cpt
where
where
cpt props@{nodeId, session} _ =
cpt {nodeId, session} _ = do
useLoader props loadCorpus' $
reload <- R.useState' 0
\corpus -> corpusLayoutView {corpus, nodeId, session}
useLoader {nodeId, reload: fst reload, session} loadCorpusWithReload $
\corpus -> corpusLayoutView {corpus, nodeId, reload, session}
type ViewProps = (
type ViewProps = (
corpus :: NodePoly Hyperdata
corpus :: NodePoly Hyperdata
, reload :: Reload
| Props
| Props
)
)
...
@@ -54,14 +60,17 @@ corpusLayoutView props = R.createElement corpusLayoutViewCpt props []
...
@@ -54,14 +60,17 @@ corpusLayoutView props = R.createElement corpusLayoutViewCpt props []
corpusLayoutViewCpt :: R.Component ViewProps
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: Hyperdata {fields}}), nodeId, session} _ = do
cpt {corpus: (NodePoly {hyperdata: Hyperdata {fields}}), nodeId,
reload,
session} _ = do
let fieldsWithIndex = A.mapWithIndex (\idx -> \t -> Tuple idx t) fields
let fieldsWithIndex = A.mapWithIndex (\idx -> \t -> Tuple idx t) fields
fieldsS <- R.useState' fieldsWithIndex
fieldsS <- R.useState' fieldsWithIndex
R.useEffect' $ do
log2 "[corpusLayoutViewCpt] reload" $ fst reload
pure $ H.div {} [
pure $ H.div {} [
H.div { className: "row" } [
H.div { className: "row" } [
H.div { className: "btn btn-default " <> (saveEnabled fieldsWithIndex fieldsS)
H.div { className: "btn btn-default " <> (saveEnabled fieldsWithIndex fieldsS)
, on: { click: onClickSave {fields: fieldsS, nodeId, session} }
, on: { click: onClickSave {fields: fieldsS, nodeId,
reload,
session} }
} [
} [
H.span { className: "glyphicon glyphicon-save" } [ ]
H.span { className: "glyphicon glyphicon-save" } [ ]
]
]
...
@@ -81,13 +90,15 @@ corpusLayoutViewCpt = R.hooksComponent "G.C.N.C.corpusLayoutView" cpt
...
@@ -81,13 +90,15 @@ corpusLayoutViewCpt = R.hooksComponent "G.C.N.C.corpusLayoutView" cpt
onClickSave :: forall e. { fields :: R.State (Array FTFieldWithIndex)
onClickSave :: forall e. { fields :: R.State (Array FTFieldWithIndex)
, nodeId :: Int
, nodeId :: Int
, reload :: R.State Int
, session :: Session } -> e -> Effect Unit
, session :: Session } -> e -> Effect Unit
onClickSave {fields: (fieldsS /\ _), nodeId, session} _ = do
onClickSave {fields: (fieldsS /\ _), nodeId,
reload: (_ /\ setReload),
session} _ = do
log2 "[corpusLayoutViewCpt] onClickSave fieldsS" fieldsS
log2 "[corpusLayoutViewCpt] onClickSave fieldsS" fieldsS
launchAff_ do
launchAff_ do
saveCorpus $ { hyperdata: Hyperdata {fields: (\(Tuple _ f) -> f) <$> fieldsS}
saveCorpus $ { hyperdata: Hyperdata {fields: (\(Tuple _ f) -> f) <$> fieldsS}
, nodeId
, nodeId
, session }
, session }
liftEffect $ setReload $ (+) 1
onClickAdd :: forall e. R.State (Array FTFieldWithIndex) -> e -> Effect Unit
onClickAdd :: forall e. R.State (Array FTFieldWithIndex) -> e -> Effect Unit
onClickAdd (_ /\ setFieldsS) _ = do
onClickAdd (_ /\ setFieldsS) _ = do
...
@@ -175,13 +186,19 @@ type LoadProps = (
...
@@ -175,13 +186,19 @@ type LoadProps = (
loadCorpus' :: Record LoadProps -> Aff (NodePoly Hyperdata)
loadCorpus' :: Record LoadProps -> Aff (NodePoly Hyperdata)
loadCorpus' {nodeId, session} = get session $ NodeAPI Corpus (Just nodeId) ""
loadCorpus' {nodeId, session} = get session $ NodeAPI Corpus (Just nodeId) ""
-- Just to make reloading effective
loadCorpusWithReload :: {reload :: Int | LoadProps} -> Aff (NodePoly Hyperdata)
loadCorpusWithReload {nodeId, reload, session} = get session $ NodeAPI Corpus (Just nodeId) $ "?_reload=" <> (show reload)
type SaveProps = (
type SaveProps = (
hyperdata :: Hyperdata
hyperdata :: Hyperdata
| LoadProps
| LoadProps
)
)
saveCorpus :: Record SaveProps -> Aff Unit
saveCorpus :: Record SaveProps -> Aff Unit
saveCorpus {hyperdata, nodeId, session} = put session (NodeAPI Corpus (Just nodeId) "") hyperdata
saveCorpus {hyperdata, nodeId, session} = do
id_ <- (put session (NodeAPI Corpus (Just nodeId) "") hyperdata) :: Aff Int
pure unit
loadCorpus :: Record LoadProps -> Aff CorpusData
loadCorpus :: Record LoadProps -> Aff CorpusData
loadCorpus {nodeId, session} = do
loadCorpus {nodeId, session} = do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment