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
142
Issues
142
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
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
gargantext
purescript-gargantext
Commits
219e41a7
Commit
219e41a7
authored
Apr 28, 2021
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[toestand] remove useState' from code
parent
3e01bbde
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
97 additions
and
85 deletions
+97
-85
Node.purs
src/Gargantext/Components/Forest/Tree/Node.purs
+1
-1
Upload.purs
...Gargantext/Components/Forest/Tree/Node/Action/Upload.purs
+63
-54
Sync.purs
src/Gargantext/Components/Forest/Tree/Node/Tools/Sync.purs
+13
-12
User.purs
src/Gargantext/Components/Nodes/Annuaire/User.purs
+8
-6
Contact.purs
src/Gargantext/Components/Nodes/Annuaire/User/Contact.purs
+11
-9
Public.purs
src/Gargantext/Components/Nodes/Home/Public.purs
+1
-3
No files found.
src/Gargantext/Components/Forest/Tree/Node.purs
View file @
219e41a7
...
...
@@ -312,7 +312,7 @@ graphNodeActionsCpt :: R.Component NodeActionsCommon
graphNodeActionsCpt = here.component "graphNodeActions" cpt where
cpt { id, session, refresh } _ =
useLoader id (graphVersions session) $ \gv ->
nodeActionsGraph { graphVersions: gv, session, id, refresh }
nodeActionsGraph { graphVersions: gv, session, id, refresh }
[]
graphVersions session graphId = GraphAPI.graphVersions { graphId, session }
listNodeActions :: R2.Leaf NodeActionsCommon
...
...
src/Gargantext/Components/Forest/Tree/Node/Action/Upload.purs
View file @
219e41a7
...
...
@@ -93,12 +93,13 @@ uploadFileViewCpt :: R.Component Props
uploadFileViewCpt = here.component "uploadFileView" cpt
where
cpt {dispatch, id, nodeType} _ = do
mFile :: R.State (Maybe UploadFile) <- R.useState' Nothing
fileType@(_ /\ setFileType) <- R.useState' CSV
lang@( _chosenLang /\ setLang) <- R.useState' EN
-- mFile :: R.State (Maybe UploadFile) <- R.useState' Nothing
mFile <- T.useBox (Nothing :: Maybe UploadFile)
fileType <- T.useBox CSV
lang <- T.useBox EN
let setFileType'
= setFileType <<< const
let setLang'
= setLang <<< const
let setFileType'
val = T.write_ val fileType
let setLang'
val = T.write_ val lang
let bodies =
[ R2.row
...
...
@@ -144,8 +145,8 @@ uploadFileViewCpt = here.component "uploadFileView" cpt
renderOptionLang :: Lang -> R.Element
renderOptionLang opt = H.option {} [ H.text $ show opt ]
onChangeContents :: forall e.
R.State
(Maybe UploadFile) -> E.SyntheticEvent_ e -> Effect Unit
onChangeContents
(mFile /\ setMFile)
e = do
onChangeContents :: forall e.
T.Box
(Maybe UploadFile) -> E.SyntheticEvent_ e -> Effect Unit
onChangeContents
mFile
e = do
let mF = R2.inputFileNameWithBlob 0 e
E.preventDefault e
E.stopPropagation e
...
...
@@ -155,15 +156,15 @@ uploadFileViewCpt = here.component "uploadFileView" cpt
--contents <- readAsText blob
--contents <- readAsDataURL blob
liftEffect $ do
setMFile $ const $ Just $ {blob: UploadFileBlob blob, name}
T.write_ (Just $ {blob: UploadFileBlob blob, name}) mFile
type UploadButtonProps =
( dispatch :: Action -> Aff Unit
, fileType ::
R.State
FileType
, fileType ::
T.Box
FileType
, id :: GT.ID
, lang ::
R.State
Lang
, mFile ::
R.State
(Maybe UploadFile)
, lang ::
T.Box
Lang
, mFile ::
T.Box
(Maybe UploadFile)
, nodeType :: GT.NodeType
)
...
...
@@ -174,36 +175,39 @@ uploadButtonCpt :: R.Component UploadButtonProps
uploadButtonCpt = here.component "uploadButton" cpt
where
cpt { dispatch
, fileType
: (fileType /\ setFileType)
, fileType
, id
, lang
: (lang /\ setLang)
, mFile
: (mFile /\ setMFile)
, lang
, mFile
, nodeType
} _ = pure
$ H.button { className: "btn btn-primary"
, "type" : "button"
, disabled
, style : { width: "100%" }
, on: {click: onClick}
} [ H.text "Upload" ]
} _ = do
fileType' <- T.useLive T.unequal fileType
mFile' <- T.useLive T.unequal mFile
let disabled = case mFile' of
Nothing -> "1"
Just _ -> ""
pure $ H.button { className: "btn btn-primary"
, "type" : "button"
, disabled
, style : { width: "100%" }
, on: {click: onClick fileType' mFile'}
} [ H.text "Upload" ]
where
disabled = case mFile of
Nothing -> "1"
Just _ -> ""
onClick e = do
let { blob, name } = unsafePartial $ fromJust mFile
log2 "[uploadButton] fileType" fileType
onClick fileType' mFile' e = do
let { blob, name } = unsafePartial $ fromJust mFile'
log2 "[uploadButton] fileType" fileType'
void $ launchAff do
case fileType of
case fileType
'
of
Arbitrary ->
dispatch $ UploadArbitraryFile (Just name) blob
_ ->
dispatch $ UploadFile nodeType fileType (Just name) blob
dispatch $ UploadFile nodeType fileType
'
(Just name) blob
liftEffect $ do
setMFile $ const $ Nothing
setFileType $ const $ CSV
setLang $ const $ EN
T.write_ Nothing mFile
T.write_ CSV fileType
T.write_ EN lang
dispatch ClosePopover
-- START File Type View
...
...
@@ -363,7 +367,8 @@ uploadTermListViewCpt :: R.Component Props
uploadTermListViewCpt = here.component "uploadTermListView" cpt
where
cpt {dispatch, id, nodeType} _ = do
mFile :: R.State (Maybe UploadFile) <- R.useState' Nothing
mFile <- T.useBox (Nothing :: Maybe UploadFile)
let body = H.input { type: "file"
, placeholder: "Choose file"
, on: {change: onChangeContents mFile}
...
...
@@ -373,15 +378,15 @@ uploadTermListViewCpt = here.component "uploadTermListView" cpt
, id
, mFile
, nodeType
}
}
]
pure $ panel [body] footer
onChangeContents :: forall e.
R.State
(Maybe UploadFile)
onChangeContents :: forall e.
T.Box
(Maybe UploadFile)
-> E.SyntheticEvent_ e
-> Effect Unit
onChangeContents
(mFile /\ setMFile)
e = do
onChangeContents
mFile
e = do
let mF = R2.inputFileNameWithBlob 0 e
E.preventDefault e
E.stopPropagation e
...
...
@@ -390,37 +395,41 @@ uploadTermListViewCpt = here.component "uploadTermListView" cpt
Just {blob, name} -> void $ launchAff do
--contents <- readAsText blob
liftEffect $ do
setMFile $ const $ Just $ { blob: UploadFileBlob blob
, name
}
T.write_ (Just $ { blob: UploadFileBlob blob
, name }) mFile
type UploadTermButtonProps =
( dispatch :: Action -> Aff Unit
, id :: Int
, mFile ::
R.State
(Maybe UploadFile)
, mFile ::
T.Box
(Maybe UploadFile)
, nodeType :: GT.NodeType
)
uploadTermButton :: R
ecord UploadTermButtonProps -> R.Element
uploadTermButton :: R
2.Leaf UploadTermButtonProps
uploadTermButton props = R.createElement uploadTermButtonCpt props []
uploadTermButtonCpt :: R.Component UploadTermButtonProps
uploadTermButtonCpt = here.component "uploadTermButton" cpt
where
cpt {dispatch, id, mFile: (mFile /\ setMFile), nodeType} _ = do
pure $ H.button {className: "btn btn-primary", disabled, on: {click: onClick}} [ H.text "Upload" ]
cpt { dispatch
, id
, mFile
, nodeType } _ = do
mFile' <- T.useLive T.unequal mFile
let disabled = case mFile' of
Nothing -> "1"
Just _ -> ""
pure $ H.button { className: "btn btn-primary"
, disabled
, on: {click: onClick mFile'}
} [ H.text "Upload" ]
where
disabled = case mFile of
Nothing -> "1"
Just _ -> ""
onClick e = do
let {name, blob} = unsafePartial $ fromJust mFile
onClick mFile' e = do
let {name, blob} = unsafePartial $ fromJust mFile'
void $ launchAff do
_ <- dispatch $ UploadFile nodeType CSV (Just name) blob
liftEffect $ do
setMFile $ const $ Nothing
T.write_ Nothing mFile
src/Gargantext/Components/Forest/Tree/Node/Tools/Sync.purs
View file @
219e41a7
...
...
@@ -5,10 +5,11 @@ import Gargantext.Prelude
import Effect.Aff (Aff, launchAff_)
import Data.Tuple.Nested ((/\))
import Data.Maybe (Maybe(..))
import Effect.Class (liftEffect)
import Data.Tuple (fst)
import Effect.Class (liftEffect)
import Reactix.DOM.HTML as H
import Reactix as R
import Toestand as T
import Gargantext.Components.GraphExplorer.API as GraphAPI
import Gargantext.Types as GT
...
...
@@ -27,9 +28,8 @@ type NodeActionsGraphProps =
, refresh :: Unit -> Aff Unit
)
nodeActionsGraph :: Record NodeActionsGraphProps -> R.Element
nodeActionsGraph p = R.createElement nodeActionsGraphCpt p []
nodeActionsGraph :: R2.Component NodeActionsGraphProps
nodeActionsGraph = R.createElement nodeActionsGraphCpt
nodeActionsGraphCpt :: R.Component NodeActionsGraphProps
nodeActionsGraphCpt = here.component "nodeActionsGraph" cpt
where
...
...
@@ -54,22 +54,23 @@ graphUpdateButtonCpt :: R.Component GraphUpdateButtonProps
graphUpdateButtonCpt = here.component "graphUpdateButton" cpt
where
cpt { id, session, refresh } _ = do
enabled <- R.useState' true
enabled <- T.useBox true
enabled' <- T.useLive T.unequal enabled
pure $ H.div { className: "update-button "
<> if
(fst enabled)
<> if
enabled'
then "enabled"
else "disabled text-muted"
} [ H.span { className: "fa fa-refresh"
, on: { click: onClick enabled } } []
, on: { click: onClick enabled
' enabled
} } []
]
where
onClick
(false /\ _)
_ = pure unit
onClick
(true /\ setEnabled) _
= do
onClick
false
_ = pure unit
onClick
true enabled
= do
launchAff_ $ do
liftEffect $
setEnabled $ const false
liftEffect $
T.write_ false enabled
g <- GraphAPI.updateGraphVersions { graphId: id, session }
liftEffect $
setEnabled $ const true
liftEffect $
T.write_ true enabled
refresh unit
pure unit
...
...
@@ -109,7 +110,7 @@ nodeListUpdateButtonCpt :: R.Component NodeListUpdateButtonProps
nodeListUpdateButtonCpt = here.component "nodeListUpdateButton" cpt
where
cpt { listId, nodeId, nodeType, session, refresh } _ = do
enabled <- R.useState'
true
-- enabled <- T.useBox
true
pure $ H.div {} [] {- { className: "update-button "
<> if (fst enabled) then "enabled" else "disabled text-muted"
...
...
src/Gargantext/Components/Nodes/Annuaire/User.purs
View file @
219e41a7
...
...
@@ -97,18 +97,20 @@ contactInfoItemCpt :: R.Component ContactInfoItemProps
contactInfoItemCpt = here.component "contactInfoItem" cpt
where
cpt {hyperdata, label, lens, onUpdateHyperdata, placeholder} _ = do
isEditing <- R.useState' false
isEditing <- T.useBox false
isEditing' <- T.useLive T.unequal isEditing
let value = (L.view cLens hyperdata) :: String
valueRef <- R.useRef value
pure $ H.div { className: "form-group row" } [
H.span { className: "col-sm-2 col-form-label" } [ H.text label ]
, item isEditing valueRef
, item isEditing
' isEditing
valueRef
]
where
cLens = L.cloneLens lens
item
(false /\ setIsEditing)
valueRef =
item
false isEditing
valueRef =
H.div { className: "input-group col-sm-6" } [
H.input { className: "form-control"
, defaultValue: placeholder'
...
...
@@ -121,8 +123,8 @@ contactInfoItemCpt = here.component "contactInfoItem" cpt
]
where
placeholder' = R.readRef valueRef
onClick _ =
setIsEditing $ const true
item
(true /\ setIsEditing)
valueRef =
onClick _ =
T.write_ true isEditing
item
true isEditing
valueRef =
H.div { className: "input-group col-sm-6" } [
inputWithEnter {
autoFocus: true
...
...
@@ -141,7 +143,7 @@ contactInfoItemCpt = here.component "contactInfoItem" cpt
]
where
onClick _ = do
setIsEditing $ const false
T.write_ true isEditing
let newHyperdata = (L.over cLens (\_ -> R.readRef valueRef) hyperdata) :: HyperdataUser
onUpdateHyperdata newHyperdata
...
...
src/Gargantext/Components/Nodes/Annuaire/User/Contact.purs
View file @
219e41a7
...
...
@@ -91,23 +91,25 @@ type ContactInfoItemProps =
, placeholder :: String
)
contactInfoItem :: R
ecord ContactInfoItemProps -> R.Element
contactInfoItem :: R
2.Leaf ContactInfoItemProps
contactInfoItem props = R.createElement contactInfoItemCpt props []
contactInfoItemCpt :: R.Component ContactInfoItemProps
contactInfoItemCpt = here.component "contactInfoItem" cpt
where
cpt {hyperdata, label, lens, onUpdateHyperdata, placeholder} _ = do
isEditing <- R.useState' false
cpt { hyperdata, label, lens, onUpdateHyperdata, placeholder } _ = do
isEditing <- T.useBox false
isEditing' <- T.useLive T.unequal isEditing
let value = (L.view cLens hyperdata) :: String
valueRef <- R.useRef value
pure $
H.div { className: "form-group row" }
[ H.span { className: "col-sm-2 col-form-label" } [ H.text label ]
, item isEditing valueRef ]
, item isEditing
' isEditing
valueRef ]
where
cLens = L.cloneLens lens
item
(false /\ setIsEditing)
valueRef =
item
false isEditing
valueRef =
H.div { className: "input-group col-sm-6" }
[ H.input
{ className: "form-control", type: "text"
...
...
@@ -116,8 +118,8 @@ contactInfoItemCpt = here.component "contactInfoItem" cpt
[ H.div { className: "input-group-text fa fa-pencil" } [] ]]
where
placeholder' = R.readRef valueRef
click _ =
setIsEditing $ const true
item
(true /\ setIsEditing)
valueRef =
click _ =
T.write_ true isEditing
item
true isEditing
valueRef =
H.div { className: "input-group col-sm-6" }
[ inputWithEnter
{ autoFocus: true
...
...
@@ -132,7 +134,7 @@ contactInfoItemCpt = here.component "contactInfoItem" cpt
[ H.div { className: "input-group-text fa fa-floppy-o" } [] ]]
where
click _ = do
setIsEditing $ const false
T.write_ false isEditing
let newHyperdata = (L.over cLens (\_ -> R.readRef valueRef) hyperdata) :: HyperdataContact
onUpdateHyperdata newHyperdata
...
...
src/Gargantext/Components/Nodes/Home/Public.purs
View file @
219e41a7
...
...
@@ -75,12 +75,10 @@ loadPublicData _l = do
renderPublic :: R2.Leaf ()
renderPublic props = R.createElement renderPublicCpt props []
renderPublicCpt :: R.Component ()
renderPublicCpt = here.component "renderPublic" cpt where
cpt _ _ = do
reload <- R.useState' 0
useLoader { reload: fst reload } loadPublicData loaded where
useLoader { reload: 0 } loadPublicData loaded where
loaded publicData = publicLayout { publicData }
publicLayout :: Record PublicDataProps -> R.Element
...
...
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