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