Commit 98d43df2 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Utils] R2.unsafeEventValue refactor

parent 87b6848d
...@@ -198,7 +198,7 @@ layoutDocview documentIdsDeleted@(_ /\ setDocumentIdsDeleted) localCategories (q ...@@ -198,7 +198,7 @@ layoutDocview documentIdsDeleted@(_ /\ setDocumentIdsDeleted) localCategories (q
] ]
] ]
onChangeQuery = mkEffectFn1 $ \e -> do onChangeQuery = mkEffectFn1 $ \e -> do
setQuery $ const $ unsafeEventValue e setQuery $ const $ R2.unsafeEventValue e
onClickTrashAll nodeId = mkEffectFn1 $ \_ -> do onClickTrashAll nodeId = mkEffectFn1 $ \_ -> do
launchAff $ deleteAllDocuments nodeId launchAff $ deleteAllDocuments nodeId
-- TODO -- TODO
...@@ -389,6 +389,3 @@ toggleSet :: forall a. Ord a => a -> Set a -> Set a ...@@ -389,6 +389,3 @@ toggleSet :: forall a. Ord a => a -> Set a -> Set a
toggleSet a s toggleSet a s
| Set.member a s = Set.delete a s | Set.member a s = Set.delete a s
| otherwise = Set.insert a s | otherwise = Set.insert a s
unsafeEventValue :: forall event. event -> String
unsafeEventValue e = (unsafeCoerce e).target.value
...@@ -22,6 +22,7 @@ import Gargantext.Config (toUrl, Path(..), End(..)) ...@@ -22,6 +22,7 @@ import Gargantext.Config (toUrl, Path(..), End(..))
import Gargantext.Config.REST (post) import Gargantext.Config.REST (post)
import Gargantext.Components.Modals.Modal (modalHide) import Gargantext.Components.Modals.Modal (modalHide)
import Gargantext.Components.Login.Types import Gargantext.Components.Login.Types
import Gargantext.Utils.Reactix as R2
-- TODO: ask for login (modal) or account creation after 15 mn when user -- TODO: ask for login (modal) or account creation after 15 mn when user
-- is not logged and has made one search at least -- is not logged and has made one search at least
...@@ -128,10 +129,10 @@ renderSpec = simpleSpec performAction render ...@@ -128,10 +129,10 @@ renderSpec = simpleSpec performAction render
, div [className "form-group"] , div [className "form-group"]
[ p [] [text state.errorMessage] [ p [] [text state.errorMessage]
, input [className "form-control", _id "id_username",maxLength "254", name "username", placeholder "username", _type "text",value state.username, onInput \e -> dispatch (SetUserName (unsafeEventValue e))] , input [className "form-control", _id "id_username",maxLength "254", name "username", placeholder "username", _type "text",value state.username, onInput \e -> dispatch (SetUserName $ R2.unsafeEventValue e)]
] ]
, div [className "form-group"] , div [className "form-group"]
[ input [className "form-control", _id "id_password", name "password", placeholder "password", _type "password",value state.password,onInput \e -> dispatch (SetPassword (unsafeEventValue e))] [ input [className "form-control", _id "id_password", name "password", placeholder "password", _type "password",value state.password,onInput \e -> dispatch (SetPassword $ R2.unsafeEventValue e)]
, div [className "clearfix"] [] , div [className "clearfix"] []
] ]
, div [className "center"] , div [className "center"]
...@@ -186,10 +187,6 @@ renderSpec = simpleSpec performAction render ...@@ -186,10 +187,6 @@ renderSpec = simpleSpec performAction render
-- ] -- ]
unsafeEventValue :: forall event. event -> String
unsafeEventValue e = (unsafeCoerce e).target.value
getAuthData :: Effect (Maybe AuthData) getAuthData :: Effect (Maybe AuthData)
getAuthData = do getAuthData = do
w <- window w <- window
......
...@@ -40,6 +40,7 @@ import Gargantext.Components.Table as T ...@@ -40,6 +40,7 @@ import Gargantext.Components.Table as T
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Components.Loader as Loader import Gargantext.Components.Loader as Loader
import Gargantext.Components.NgramsTable.Core import Gargantext.Components.NgramsTable.Core
import Gargantext.Utils.Reactix as R2
type State = type State =
CoreState CoreState
...@@ -119,7 +120,7 @@ tableContainer { pageParams ...@@ -119,7 +120,7 @@ tableContainer { pageParams
, name "search", placeholder "Search" , name "search", placeholder "Search"
, _type "value" , _type "value"
, value pageParams.searchQuery , value pageParams.searchQuery
, onInput \e -> setSearchQuery (unsafeEventValue e) , onInput \e -> setSearchQuery (R2.unsafeEventValue e)
] ]
, div [] ( , div [] (
if A.null props.tableBody && pageParams.searchQuery /= "" then [ if A.null props.tableBody && pageParams.searchQuery /= "" then [
...@@ -134,7 +135,7 @@ tableContainer { pageParams ...@@ -134,7 +135,7 @@ tableContainer { pageParams
[ select [ _id "picklistmenu" [ select [ _id "picklistmenu"
, className "form-control custom-select" , className "form-control custom-select"
, value (maybe "" show pageParams.termListFilter) , value (maybe "" show pageParams.termListFilter)
, onChange (\e -> setTermListFilter $ readTermList $ unsafeEventValue e) , onChange (\e -> setTermListFilter $ readTermList $ R2.unsafeEventValue e)
] $ map optps1 termLists ] $ map optps1 termLists
] ]
] ]
...@@ -143,7 +144,7 @@ tableContainer { pageParams ...@@ -143,7 +144,7 @@ tableContainer { pageParams
[ select [ _id "picktermtype" [ select [ _id "picktermtype"
, className "form-control custom-select" , className "form-control custom-select"
, value (maybe "" show pageParams.termSizeFilter) , value (maybe "" show pageParams.termSizeFilter)
, onChange (\e -> setTermSizeFilter $ readTermSize $ unsafeEventValue e) , onChange (\e -> setTermSizeFilter $ readTermSize $ R2.unsafeEventValue e)
] $ map optps1 termSizes ] $ map optps1 termSizes
] ]
] ]
...@@ -420,6 +421,3 @@ optps1 :: forall a. Show a => { desc :: String, mval :: Maybe a } -> ReactElemen ...@@ -420,6 +421,3 @@ optps1 :: forall a. Show a => { desc :: String, mval :: Maybe a } -> ReactElemen
optps1 { desc, mval } = option [value val] [text desc] optps1 { desc, mval } = option [value val] [text desc]
where where
val = maybe "" show mval val = maybe "" show mval
unsafeEventValue :: forall event. event -> String
unsafeEventValue e = (unsafeCoerce e).target.value
...@@ -14,6 +14,7 @@ import Thermite (PerformAction, Render, Spec, modifyState_, simpleSpec, StateCoT ...@@ -14,6 +14,7 @@ import Thermite (PerformAction, Render, Spec, modifyState_, simpleSpec, StateCoT
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Utils.Reactix as R2
type TableContainerProps = type TableContainerProps =
{ pageSizeControl :: ReactElement { pageSizeControl :: ReactElement
...@@ -218,7 +219,7 @@ sizeDD :: PageSizes -> (Action -> Effect Unit) -> ReactElement ...@@ -218,7 +219,7 @@ sizeDD :: PageSizes -> (Action -> Effect Unit) -> ReactElement
sizeDD ps d sizeDD ps d
= span [] = span []
[ select [ className "form-control" [ select [ className "form-control"
, onChange (\e -> d (ChangePageSize $ string2PageSize $ (unsafeCoerce e).target.value)) , onChange (\e -> d (ChangePageSize $ string2PageSize $ R2.unsafeEventValue e))
] $ map (optps ps) aryPS ] $ map (optps ps) aryPS
] ]
......
...@@ -695,6 +695,3 @@ uploadFile id fileType (UploadFileContents fileContents) = postWwwUrlencoded url ...@@ -695,6 +695,3 @@ uploadFile id fileType (UploadFileContents fileContents) = postWwwUrlencoded url
fnTransform :: LNode -> FTree fnTransform :: LNode -> FTree
fnTransform n = NTree n [] fnTransform n = NTree n []
unsafeEventValue :: forall event. event -> String
unsafeEventValue e = (unsafeCoerce e).target.value
...@@ -7,7 +7,8 @@ import React.DOM (br', button, div, input, text) ...@@ -7,7 +7,8 @@ import React.DOM (br', button, div, input, text)
import React.DOM.Props (_id, _type, className, name, onClick, onInput, placeholder, value) import React.DOM.Props (_id, _type, className, name, onClick, onInput, placeholder, value)
import Routing.Hash (setHash) import Routing.Hash (setHash)
import Thermite (PerformAction, Render, Spec, modifyState, simpleSpec) import Thermite (PerformAction, Render, Spec, modifyState, simpleSpec)
import Unsafe.Coerce (unsafeCoerce)
import Gargantext.Utils.Reactix as R2
type State = type State =
{ {
...@@ -26,20 +27,16 @@ data Action ...@@ -26,20 +27,16 @@ data Action
= GO = GO
| SetQuery String | SetQuery String
performAction :: PerformAction State {} Action
performAction (SetQuery q) _ _ = void do
modifyState $ _ { query = q }
unsafeEventValue :: forall event. event -> String performAction GO _ _ = void do
unsafeEventValue e = (unsafeCoerce e).target.value liftEffect $ setHash "/addCorpus"
searchSpec :: Spec State {} Action searchSpec :: Spec State {} Action
searchSpec = simpleSpec performAction render searchSpec = simpleSpec performAction render
where where
performAction :: PerformAction State {} Action
performAction (SetQuery q) _ _ = void do
modifyState $ _ { query = q }
performAction GO _ _ = void do
liftEffect $ setHash "/addCorpus"
render :: Render State {} Action render :: Render State {} Action
render dispatch _ state _ = render dispatch _ state _ =
[ div [className "container1"] [] [ div [className "container1"] []
...@@ -56,7 +53,7 @@ searchSpec = simpleSpec performAction render ...@@ -56,7 +53,7 @@ searchSpec = simpleSpec performAction render
, placeholder "Query, URL or FILE (works best with Firefox or Chromium browsers)" , placeholder "Query, URL or FILE (works best with Firefox or Chromium browsers)"
, _type "text" , _type "text"
, value state.query , value state.query
, onInput \e -> dispatch (SetQuery (unsafeEventValue e)) , onInput \e -> dispatch (SetQuery (R2.unsafeEventValue e))
] ]
, br' , br'
] ]
......
...@@ -89,3 +89,7 @@ select = createDOMElement "select" ...@@ -89,3 +89,7 @@ select = createDOMElement "select"
effToggler :: forall e. R.State Boolean -> EffectFn1 e Unit effToggler :: forall e. R.State Boolean -> EffectFn1 e Unit
effToggler (value /\ setValue) = mkEffectFn1 $ \e -> setValue $ const $ not value effToggler (value /\ setValue) = mkEffectFn1 $ \e -> setValue $ const $ not value
unsafeEventValue :: forall event. event -> String
unsafeEventValue e = (unsafeCoerce e).target.value
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