Commit 219e41a7 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[toestand] remove useState' from code

parent 3e01bbde
...@@ -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
......
...@@ -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
mFile' <- T.useLive T.unequal mFile
let disabled = case mFile' of
Nothing -> "1"
Just _ -> ""
pure $ H.button { className: "btn btn-primary"
, "type" : "button" , "type" : "button"
, disabled , disabled
, style : { width: "100%" } , style : { width: "100%" }
, on: {click: onClick} , on: {click: onClick fileType' mFile'}
} [ H.text "Upload" ] } [ 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}
...@@ -378,10 +383,10 @@ uploadTermListViewCpt = here.component "uploadTermListView" cpt ...@@ -378,10 +383,10 @@ uploadTermListViewCpt = here.component "uploadTermListView" cpt
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 :: Record UploadTermButtonProps -> R.Element uploadTermButton :: R2.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
where , mFile
disabled = case mFile of , nodeType } _ = do
mFile' <- T.useLive T.unequal mFile
let disabled = case mFile' of
Nothing -> "1" Nothing -> "1"
Just _ -> "" Just _ -> ""
onClick e = do pure $ H.button { className: "btn btn-primary"
let {name, blob} = unsafePartial $ fromJust mFile , disabled
, on: {click: onClick mFile'}
} [ H.text "Upload" ]
where
onClick mFile' 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
...@@ -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"
......
...@@ -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
......
...@@ -91,23 +91,25 @@ type ContactInfoItemProps = ...@@ -91,23 +91,25 @@ type ContactInfoItemProps =
, placeholder :: String , placeholder :: String
) )
contactInfoItem :: Record ContactInfoItemProps -> R.Element contactInfoItem :: R2.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
......
...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment