aboutsummaryrefslogtreecommitdiff
path: root/client/src/Component/Select.hs
diff options
context:
space:
mode:
authorJoris2019-10-22 22:26:38 +0200
committerJoris2019-10-22 22:26:38 +0200
commit613ffccac4b3ab25c6d4c631fab757da0b35acf6 (patch)
tree13e448af89f4079bb62d7ce8b5a44b6a64515129 /client/src/Component/Select.hs
parent80f09e8b3a5c856e60922a73c9161a8c5392e4d4 (diff)
downloadbudget-613ffccac4b3ab25c6d4c631fab757da0b35acf6.tar.gz
budget-613ffccac4b3ab25c6d4c631fab757da0b35acf6.tar.bz2
budget-613ffccac4b3ab25c6d4c631fab757da0b35acf6.zip
Harmonize view component code style
Diffstat (limited to 'client/src/Component/Select.hs')
-rw-r--r--client/src/Component/Select.hs56
1 files changed, 28 insertions, 28 deletions
diff --git a/client/src/Component/Select.hs b/client/src/Component/Select.hs
index 102f554..375ae06 100644
--- a/client/src/Component/Select.hs
+++ b/client/src/Component/Select.hs
@@ -1,7 +1,7 @@
module Component.Select
- ( SelectIn(..)
- , SelectOut(..)
- , select
+ ( view
+ , In(..)
+ , Out(..)
) where
import Data.Map (Map)
@@ -15,58 +15,58 @@ import qualified Reflex.Dom as R
import qualified Util.Validation as ValidationUtil
-data (Reflex t) => SelectIn t a b c = SelectIn
- { _selectIn_label :: Text
- , _selectIn_initialValue :: a
- , _selectIn_value :: Event t a
- , _selectIn_values :: Dynamic t (Map a Text)
- , _selectIn_reset :: Event t b
- , _selectIn_isValid :: a -> Validation Text a
- , _selectIn_validate :: Event t c
+data (Reflex t) => In t a b c = In
+ { _in_label :: Text
+ , _in_initialValue :: a
+ , _in_value :: Event t a
+ , _in_values :: Dynamic t (Map a Text)
+ , _in_reset :: Event t b
+ , _in_isValid :: a -> Validation Text a
+ , _in_validate :: Event t c
}
-data SelectOut t a = SelectOut
- { _selectOut_raw :: Dynamic t a
- , _selectOut_value :: Dynamic t (Validation Text a)
+data Out t a = Out
+ { _out_raw :: Dynamic t a
+ , _out_value :: Dynamic t (Validation Text a)
}
-select :: forall t m a b c. (Ord a, MonadWidget t m) => SelectIn t a b c -> m (SelectOut t a)
-select selectIn = do
+view :: forall t m a b c. (Ord a, MonadWidget t m) => In t a b c -> m (Out t a)
+view input = do
rec
let containerAttr = R.ffor showedError (\e ->
M.singleton "class" $ T.intercalate " "
- [ "selectInput"
+ [ "input"
, if Maybe.isJust e then "error" else ""
])
validatedValue =
- fmap (_selectIn_isValid selectIn) value
+ fmap (_in_isValid input) value
maybeError =
fmap ValidationUtil.maybeError validatedValue
showedError <- R.holdDyn Nothing $ R.leftmost
- [ Nothing <$ _selectIn_reset selectIn
+ [ Nothing <$ _in_reset input
, R.updated maybeError
- , R.attachWith const (R.current maybeError) (_selectIn_validate selectIn)
+ , R.attachWith const (R.current maybeError) (_in_validate input)
]
value <- R.elDynAttr "div" containerAttr $ do
- let initialValue = _selectIn_initialValue selectIn
+ let initialValue = _in_initialValue input
let setValue = R.leftmost
- [ initialValue <$ (_selectIn_reset selectIn)
- , _selectIn_value selectIn
+ [ initialValue <$ (_in_reset input)
+ , _in_value input
]
value <- R.el "label" $ do
R.divClass "label" $
- R.text (_selectIn_label selectIn)
+ R.text (_in_label input)
R._dropdown_value <$>
R.dropdown
initialValue
- (_selectIn_values selectIn)
+ (_in_values input)
(R.def { R._dropdownConfig_setValue = setValue })
R.divClass "errorMessage" . R.dynText $
@@ -74,7 +74,7 @@ select selectIn = do
return value
- return SelectOut
- { _selectOut_raw = value
- , _selectOut_value = validatedValue
+ return Out
+ { _out_raw = value
+ , _out_value = validatedValue
}