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
68298c5b
Commit
68298c5b
authored
Mar 15, 2021
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[toestand] ngramsTable: state is a box now
parent
c5b11698
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
128 additions
and
113 deletions
+128
-113
NgramsTable.purs
src/Gargantext/Components/NgramsTable.purs
+100
-88
Core.purs
src/Gargantext/Components/NgramsTable/Core.purs
+16
-17
Document.purs
src/Gargantext/Components/Nodes/Corpus/Document.purs
+12
-8
No files found.
src/Gargantext/Components/NgramsTable.purs
View file @
68298c5b
This diff is collapsed.
Click to expand it.
src/Gargantext/Components/NgramsTable/Core.purs
View file @
68298c5b
...
...
@@ -974,12 +974,12 @@ putNgramsPatches :: forall s. CoreParams s -> VersionedNgramsPatches -> Aff Vers
putNgramsPatches { listIds, nodeId, session, tabType } = put session putNgrams
where putNgrams = PutNgrams tabType (head listIds) Nothing (Just nodeId)
syncPatches :: forall p s. CoreParams p ->
R.State
(CoreState s) -> (Unit -> Aff Unit) -> Effect Unit
syncPatches props
({ ngramsLocalPatch: ngramsLocalPatch@{ ngramsPatches }
, ngramsStagePatch
, ngramsValid
Patch
, ngramsVersion
} /\ setState) callback = do
syncPatches :: forall p s. CoreParams p ->
T.Box
(CoreState s) -> (Unit -> Aff Unit) -> Effect Unit
syncPatches props
state callback = do
{ ngramsLocalPatch: ngramsLocalPatch@{ ngramsPatches }
, ngramsStage
Patch
, ngramsValidPatch
, ngramsVersion } <- T.read state
when (isEmptyNgramsTablePatch ngramsStagePatch) $ do
let pt = Versioned { data: ngramsPatches, version: ngramsVersion }
launchAff_ $ do
...
...
@@ -987,7 +987,7 @@ syncPatches props ({ ngramsLocalPatch: ngramsLocalPatch@{ ngramsPatches }
callback unit
liftEffect $ do
log2 "[syncPatches] setting state, newVersion" newVersion
setState $
\s ->
T.modify_ (
\s ->
-- I think that sometimes this setState does not fully go through.
-- This is an issue because the version number does not get updated and the subsequent calls
-- can mess up the patches.
...
...
@@ -997,7 +997,7 @@ syncPatches props ({ ngramsLocalPatch: ngramsLocalPatch@{ ngramsPatches }
, ngramsValidPatch = fromNgramsPatches newPatch <> ngramsLocalPatch <> s.ngramsValidPatch
-- First the already valid patch, then the local patch, then the newly received newPatch.
, ngramsVersion = newVersion
}
}
) state
log2 "[syncPatches] ngramsVersion" newVersion
pure unit
...
...
@@ -1027,10 +1027,9 @@ syncPatchesAsync props@{ listIds, tabType }
log2 "[syncPatches] ngramsVersion" newVersion
-}
commitPatch :: forall s. Versioned NgramsTablePatch -> R.State (CoreState s) -> Effect Unit
commitPatch (Versioned {version, data: tablePatch}) (_ /\ setState) = do
setState $ \s ->
s { ngramsLocalPatch = tablePatch <> s.ngramsLocalPatch }
commitPatch :: forall s. NgramsTablePatch -> T.Box (CoreState s) -> Effect Unit
commitPatch tablePatch state = do
T.modify_ (\s -> s { ngramsLocalPatch = tablePatch <> s.ngramsLocalPatch }) state
-- First we apply the patches we have locally and then the new patch (tablePatch).
loadNgramsTable :: PageParams -> Aff VersionedNgramsTable
...
...
@@ -1096,13 +1095,13 @@ data Action
type CoreDispatch = CoreAction -> Effect Unit
type Dispatch = Action -> Effect Unit
coreDispatch :: forall p s. CoreParams p ->
R.State
(CoreState s) -> CoreDispatch
coreDispatch :: forall p s. CoreParams p ->
T.Box
(CoreState s) -> CoreDispatch
coreDispatch path state (Synchronize { afterSync }) =
syncPatches path state afterSync
coreDispatch _ state
@({ngramsVersion} /\ _)
(CommitPatch pt) =
commitPatch
(Versioned {version: ngramsVersion, data: pt})
state
coreDispatch _
(_ /\ setState)
ResetPatches =
setState $ \s -> s { ngramsLocalPatch = { ngramsPatches: mempty } }
coreDispatch _ state (CommitPatch pt) =
commitPatch
pt
state
coreDispatch _
state
ResetPatches =
T.modify_ (\s -> s { ngramsLocalPatch = { ngramsPatches: mempty } }) state
isSingleNgramsTerm :: NgramsTerm -> Boolean
isSingleNgramsTerm nt = isSingleTerm $ ngramsTermText nt
...
...
src/Gargantext/Components/Nodes/Corpus/Document.purs
View file @
68298c5b
...
...
@@ -9,6 +9,7 @@ import Effect.Aff (Aff)
import Reactix as R
import Reactix.DOM.HTML as H
import Record as Record
import Toestand as T
import Gargantext.Prelude (bind, pure, show, unit, ($), (<>), (<$>), (<<<))
...
...
@@ -43,12 +44,12 @@ docViewWrapperCpt :: R.Component Props
docViewWrapperCpt = here.component "docViewWrapper" cpt
where
cpt props@{ loaded } _ = do
state <-
R.useState'
$ initialState { loaded }
state <-
T.useBox
$ initialState { loaded }
pure $ docView (Record.merge props { state }) []
type DocViewProps = (
state ::
R.State
State
state ::
T.Box
State
| Props
)
...
...
@@ -60,8 +61,9 @@ docViewCpt = here.component "docView" cpt
where
cpt { path
, loaded: loaded@{ ngramsTable: Versioned { data: initTable }, document }
, state
: state@({ ngramsVersion: version, ngramsLocalPatch } /\ _)
, state
} _children = do
state'@{ ngramsLocalPatch, ngramsVersion: version } <- T.useLive T.unequal state
let
afterSync = \_ -> pure unit
...
...
@@ -74,6 +76,13 @@ docViewCpt = here.component "docView" cpt
then [ autoUpdate { duration: 5000, effect: dispatch $ Synchronize { afterSync } } ]
else []
ngrams = applyNgramsPatches state' initTable
annotate text = AnnotatedField.annotatedField { ngrams, setTermList, text }
setTermListOrAddA ngram Nothing = addNewNgramA ngram
setTermListOrAddA ngram (Just oldList) = setTermListA ngram <<< replace oldList
setTermList ngram mOldList = dispatch <<< setTermListOrAddA (findNgramRoot ngrams ngram) mOldList
pure $ H.div {} $
autoUpd <> syncResetBtns <>
--DEBUG
...
...
@@ -95,17 +104,12 @@ docViewCpt = here.component "docView" cpt
]]]]
where
dispatch = coreDispatch path state
ngrams = applyNgramsPatches (fst state) initTable
annotate text = AnnotatedField.annotatedField { ngrams, setTermList, text }
badge s = H.span { className: "badge badge-default badge-pill" } [ H.text s ]
badgeLi s =
H.span { className: "list-group-item-heading" }
[ H.span { className: "badge-container" }
[ H.span { className: "badge badge-default badge-pill" } [ H.text s ] ]]
li' = H.li { className: "list-group-item justify-content-between" }
setTermListOrAddA ngram Nothing = addNewNgramA ngram
setTermListOrAddA ngram (Just oldList) = setTermListA ngram <<< replace oldList
setTermList ngram mOldList = dispatch <<< setTermListOrAddA (findNgramRoot ngrams ngram) mOldList
-- Here the use of findNgramRoot makes that we always target the root of an ngram group.
text' x = H.span { className: "list-group-item-text" } [ H.text $ fromMaybe "Nothing" x ]
NodePoly {hyperdata: Document doc} = document
...
...
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