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
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
......
......@@ -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"
} _ = 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}
, 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}
......@@ -378,10 +383,10 @@ uploadTermListViewCpt = here.component "uploadTermListView" cpt
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 :: Record UploadTermButtonProps -> R.Element
uploadTermButton :: R2.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" ]
where
disabled = case mFile of
cpt { dispatch
, id
, mFile
, nodeType } _ = do
mFile' <- T.useLive T.unequal mFile
let disabled = case mFile' of
Nothing -> "1"
Just _ -> ""
onClick e = do
let {name, blob} = unsafePartial $ fromJust mFile
pure $ H.button { className: "btn btn-primary"
, disabled
, on: {click: onClick mFile'}
} [ H.text "Upload" ]
where
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
......@@ -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"
......
......@@ -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
......
......@@ -91,23 +91,25 @@ type ContactInfoItemProps =
, placeholder :: String
)
contactInfoItem :: Record ContactInfoItemProps -> R.Element
contactInfoItem :: R2.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
......
......@@ -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
......
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