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
871130cb
Commit
871130cb
authored
Mar 15, 2021
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[toestand] more state refactoring
parent
68298c5b
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
61 additions
and
30 deletions
+61
-30
Series.purs
src/Gargantext/Components/Charts/Options/Series.purs
+7
-3
Types.purs
src/Gargantext/Components/DocsTable/Types.purs
+5
-0
FacetsTable.purs
src/Gargantext/Components/FacetsTable.purs
+6
-3
Common.purs
src/Gargantext/Components/Nodes/Corpus/Chart/Common.purs
+4
-2
Histo.purs
src/Gargantext/Components/Nodes/Corpus/Chart/Histo.purs
+10
-3
Metrics.purs
src/Gargantext/Components/Nodes/Corpus/Chart/Metrics.purs
+7
-4
Pie.purs
src/Gargantext/Components/Nodes/Corpus/Chart/Pie.purs
+7
-2
Tree.purs
src/Gargantext/Components/Nodes/Corpus/Chart/Tree.purs
+1
-0
Types.purs
src/Gargantext/Components/Nodes/Types.purs
+0
-2
Loader.purs
src/Gargantext/Hooks/Loader.purs
+14
-10
Types.purs
src/Gargantext/Types.purs
+0
-1
No files found.
src/Gargantext/Components/Charts/Options/Series.purs
View file @
871130cb
module Gargantext.Components.Charts.Options.Series where
import Prelude (class
Show, bind, map, pure, show, ($), (+), (<<<), (<>)
)
import Prelude (class
Eq, class Show, bind, map, pure, show, ($), (+), (<<<), (<>), eq
)
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson, (.:), (~>), (:=))
import Data.Argonaut.Core (jsonEmptyObject)
import Data.Array (foldl)
import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..), maybe)
import Record.Unsafe (unsafeSet)
import Unsafe.Coerce (unsafeCoerce)
...
...
@@ -186,11 +187,14 @@ toJsTree maybeSurname (TreeNode x) =
name = maybe "" (\x' -> x' <> ">") maybeSurname <> x.name
data TreeNode = TreeNode {
name :: String
children :: Array TreeNode
, name :: String
, value :: Int
, children :: Array TreeNode
}
derive instance genericTreeNode :: Generic TreeNode _
instance eqTreeNode :: Eq TreeNode where
eq (TreeNode n1) (TreeNode n2) = eq n1 n2
instance decodeTreeNode :: DecodeJson TreeNode where
decodeJson json = do
obj <- decodeJson json
...
...
src/Gargantext/Components/DocsTable/Types.purs
View file @
871130cb
module Gargantext.Components.DocsTable.Types where
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, jsonEmptyObject, (.:), (:=), (~>))
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq)
import Data.Map (Map)
import Data.Map as Map
import Data.Maybe (Maybe(..))
...
...
@@ -24,6 +26,9 @@ newtype DocumentsView
, title :: String
, url :: String
}
derive instance genericDocumentsView :: Generic DocumentsView _
instance eqDocumentsView :: Eq DocumentsView where
eq = genericEq
{-
derive instance genericDocumentsView :: Generic DocumentsView _
...
...
src/Gargantext/Components/FacetsTable.purs
View file @
871130cb
...
...
@@ -4,10 +4,11 @@
module Gargantext.Components.FacetsTable where
import Prelude
( class Show, Unit, bind, const, discard, identity, mempty, not
( class
Eq, class
Show, Unit, bind, const, discard, identity, mempty, not
, otherwise, pure, unit, void, ($), (*>), (<$>), (<<<), (<>), (==), (>) )
import Data.Argonaut (class EncodeJson, jsonEmptyObject, (:=), (~>))
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq)
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Sequence (Seq)
...
...
@@ -68,7 +69,8 @@ newtype Pair =
}
derive instance genericPair :: Generic Pair _
instance eqPair :: Eq Pair where
eq = genericEq
instance showPair :: Show Pair where
show = genericShow
...
...
@@ -90,7 +92,8 @@ newtype DocumentsView =
}
derive instance genericDocumentsView :: Generic DocumentsView _
instance eqDocumentsView :: Eq DocumentsView where
eq = genericEq
instance showDocumentsView :: Show DocumentsView where
show = genericShow
...
...
src/Gargantext/Components/Nodes/Corpus/Chart/Common.purs
View file @
871130cb
...
...
@@ -48,11 +48,13 @@ type MetricsWithCacheLoadViewProps res ret = (
| MetricsProps
)
metricsWithCacheLoadView :: forall res ret. DecodeJson res =>
metricsWithCacheLoadView :: forall res ret.
Eq ret => DecodeJson res =>
Record (MetricsWithCacheLoadViewProps res ret) -> R.Element
metricsWithCacheLoadView p = R.createElement metricsWithCacheLoadViewCpt p []
metricsWithCacheLoadViewCpt :: forall res ret. DecodeJson res =>
metricsWithCacheLoadViewCpt :: forall res ret.
Eq ret => DecodeJson res =>
R.Component (MetricsWithCacheLoadViewProps res ret)
metricsWithCacheLoadViewCpt = here.component "metricsWithCacheLoadView" cpt
where
...
...
src/Gargantext/Components/Nodes/Corpus/Chart/Histo.purs
View file @
871130cb
...
...
@@ -2,6 +2,8 @@ module Gargantext.Components.Nodes.Corpus.Chart.Histo where
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson, (.:), (~>), (:=))
import Data.Argonaut.Core (jsonEmptyObject)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq)
import Data.Maybe (Maybe(..))
import Data.Tuple.Nested ((/\))
import Effect.Aff (Aff)
...
...
@@ -9,6 +11,8 @@ import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Prelude (class Eq, bind, map, pure, ($), (==))
import Gargantext.Components.Charts.Options.Color (grey)
import Gargantext.Components.Charts.Options.Data (dataSerie)
import Gargantext.Components.Charts.Options.ECharts (Options(..), chart, xAxis', yAxis')
...
...
@@ -17,7 +21,6 @@ import Gargantext.Components.Charts.Options.Series (seriesBarD1)
import Gargantext.Components.Nodes.Corpus.Chart.Common (metricsWithCacheLoadView)
import Gargantext.Components.Nodes.Corpus.Chart.Types (MetricsProps, Path, Props, ReloadPath)
import Gargantext.Hooks.Loader (HashedResponse(..))
import Gargantext.Prelude (bind, map, pure, ($), (==))
import Gargantext.Routes (SessionRoute(..))
import Gargantext.Sessions (Session, get)
import Gargantext.Types (ChartType(..))
...
...
@@ -31,7 +34,9 @@ here = R2.here "Gargantext.Components.Nodes.Corpus.Chart.Histo"
newtype ChartMetrics = ChartMetrics {
"data" :: HistoMetrics
}
derive instance genericChartMetrics :: Generic ChartMetrics _
instance eqChartMetrics :: Eq ChartMetrics where
eq = genericEq
instance decodeChartMetrics :: DecodeJson ChartMetrics where
decodeJson json = do
obj <- decodeJson json
...
...
@@ -39,7 +44,9 @@ instance decodeChartMetrics :: DecodeJson ChartMetrics where
pure $ ChartMetrics { "data": d }
newtype HistoMetrics = HistoMetrics { dates :: Array String, count :: Array Number }
derive instance genericHistoMetrics :: Generic HistoMetrics _
instance eqHistoMetrics :: Eq HistoMetrics where
eq = genericEq
instance decodeHistoMetrics :: DecodeJson HistoMetrics where
decodeJson json = do
obj <- decodeJson json
...
...
src/Gargantext/Components/Nodes/Corpus/Chart/Metrics.purs
View file @
871130cb
module Gargantext.Components.Nodes.Corpus.Chart.Metrics where
import Gargantext.Prelude (bind, negate, pure, ($), (<$>), (<>))
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson, (.:), (~>), (:=))
import Data.Argonaut.Core (jsonEmptyObject)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq)
import Data.Map as Map
import Data.Map (Map)
import Data.Maybe (Maybe(..))
...
...
@@ -14,6 +14,8 @@ import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Prelude (class Eq, bind, negate, pure, ($), (<$>), (<>))
import Gargantext.Components.Charts.Options.ECharts (Options(..), chart, yAxis')
import Gargantext.Components.Charts.Options.Type (xAxis)
import Gargantext.Components.Charts.Options.Series (Series, seriesScatterD2)
...
...
@@ -40,7 +42,9 @@ newtype Metric = Metric
, y :: Number
, cat :: TermList
}
derive instance genericMetric :: Generic Metric _
instance eqMetric :: Eq Metric where
eq = genericEq
instance decodeMetric :: DecodeJson Metric where
decodeJson json = do
obj <- decodeJson json
...
...
@@ -49,7 +53,6 @@ instance decodeMetric :: DecodeJson Metric where
y <- obj .: "y"
cat <- obj .: "cat"
pure $ Metric { label, x, y, cat }
instance encodeMetric :: EncodeJson Metric where
encodeJson (Metric { label, x, y, cat }) =
"label" := encodeJson label
...
...
src/Gargantext/Components/Nodes/Corpus/Chart/Pie.purs
View file @
871130cb
module Gargantext.Components.Nodes.Corpus.Chart.Pie where
import Gargantext.Prelude (bind, map, pure, ($), (==), (>))
import Data.Argonaut (class DecodeJson, class EncodeJson, decodeJson, encodeJson, (.:), (~>), (:=))
import Data.Argonaut.Core (jsonEmptyObject)
import Data.Array (zip, filter)
import Data.Array as A
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq)
import Data.Maybe (Maybe(..))
import Data.String (take, joinWith, Pattern(..), split, length)
import Data.Tuple (Tuple(..))
...
...
@@ -14,6 +15,8 @@ import Reactix as R
import Reactix.DOM.HTML as H
import Toestand as T
import Gargantext.Prelude (class Eq, bind, map, pure, ($), (==), (>))
import Gargantext.Components.Charts.Options.Color (blue)
import Gargantext.Components.Charts.Options.Data (dataSerie)
import Gargantext.Components.Charts.Options.ECharts (Options(..), chart, xAxis', yAxis')
...
...
@@ -47,7 +50,9 @@ newtype HistoMetrics = HistoMetrics
{ dates :: Array String
, count :: Array Number
}
derive instance genericHistoMetrics :: Generic HistoMetrics _
instance eqHistoMetrics :: Eq HistoMetrics where
eq = genericEq
instance decodeHistoMetrics :: DecodeJson HistoMetrics where
decodeJson json = do
obj <- decodeJson json
...
...
src/Gargantext/Components/Nodes/Corpus/Chart/Tree.purs
View file @
871130cb
...
...
@@ -81,6 +81,7 @@ treeCpt = here.component "tree" cpt
where
cpt {path, session} _ = do
reload <- T.useBox T2.newReload
pure $ metricsWithCacheLoadView {
getMetricsHash
, handleResponse
...
...
src/Gargantext/Components/Nodes/Types.purs
View file @
871130cb
...
...
@@ -35,10 +35,8 @@ newtype Field a =
type FTField = Field FieldType
derive instance genericFTField :: Generic (Field FieldType) _
instance eqFTField :: Eq (Field FieldType) where
eq = genericEq
instance showFTField :: Show (Field FieldType) where
show = genericShow
...
...
src/Gargantext/Hooks/Loader.purs
View file @
871130cb
...
...
@@ -8,6 +8,7 @@ import Effect.Aff (Aff, launchAff_, throwError)
import Effect.Class (liftEffect)
import Effect.Exception (error)
import Reactix as R
import Toestand as T
import Gargantext.Components.LoadingSpinner (loadingSpinner)
import Gargantext.Prelude
...
...
@@ -77,35 +78,38 @@ type LoaderWithCacheAPIProps path res ret = (
useLoaderWithCacheAPI :: forall path res ret.
Eq path => DecodeJson res =>
Eq
ret => Eq
path => DecodeJson res =>
Record (LoaderWithCacheAPIProps path res ret)
-> R.Hooks R.Element
useLoaderWithCacheAPI { cacheEndpoint, handleResponse, mkRequest, path, renderer } = do
state <- R.useState' Nothing
state <- T.useBox Nothing
state' <- T.useLive T.unequal state
useCachedAPILoaderEffect { cacheEndpoint
, handleResponse
, mkRequest
, path
, state }
pure $ maybe (loadingSpinner {}) renderer
(fst state)
pure $ maybe (loadingSpinner {}) renderer
state'
type LoaderWithCacheAPIEffectProps path res ret = (
cacheEndpoint :: path -> Aff Hash
, handleResponse :: HashedResponse res -> ret
, mkRequest :: path -> GUC.Request
, path :: path
, state
:: R.State
(Maybe ret)
, state
:: T.Box
(Maybe ret)
)
useCachedAPILoaderEffect :: forall path res ret.
Eq path => DecodeJson res =>
Eq
ret => Eq
path => DecodeJson res =>
Record (LoaderWithCacheAPIEffectProps path res ret)
-> R.Hooks Unit
useCachedAPILoaderEffect { cacheEndpoint
, handleResponse
, mkRequest
, path
, state: state@(state' /\ setState) } = do
, state } = do
state' <- T.useLive T.unequal state
oPath <- R.useRef path
R.useEffect' $ do
...
...
@@ -131,4 +135,4 @@ useCachedAPILoaderEffect { cacheEndpoint
else
throwError $ error $ "Fetched clean cache but hashes don't match: " <> h <> " != " <> cacheReal
liftEffect $ do
setState $ const $ Just $ handleResponse val
T.write_ (Just $ handleResponse val) state
src/Gargantext/Types.purs
View file @
871130cb
...
...
@@ -32,7 +32,6 @@ flipHanded l r LeftHanded = R.fragment [r, l]
flipHanded l r RightHanded = R.fragment [l, r]
derive instance ed :: Generic Handed _
instance eqHanded :: Eq Handed where
eq = genericEq
...
...
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