aboutsummaryrefslogtreecommitdiff
path: root/client/src/View/Payment
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/View/Payment')
-rw-r--r--client/src/View/Payment/Form.hs1
-rw-r--r--client/src/View/Payment/Payment.hs18
-rw-r--r--client/src/View/Payment/Reducer.hs30
3 files changed, 23 insertions, 26 deletions
diff --git a/client/src/View/Payment/Form.hs b/client/src/View/Payment/Form.hs
index 99dce13..064b5b3 100644
--- a/client/src/View/Payment/Form.hs
+++ b/client/src/View/Payment/Form.hs
@@ -113,6 +113,7 @@ view input cancel = do
setCategory <-
R.debounce (1 :: NominalDiffTime) (R.updated $ Input._out_raw name)
+ >>= (return . R.ffilter (\name -> T.length name >= 3))
>>= (Ajax.get . (fmap ("/api/payment/category?name=" <>)))
>>= (return . R.mapMaybe (join . EitherUtil.eitherToMaybe))
diff --git a/client/src/View/Payment/Payment.hs b/client/src/View/Payment/Payment.hs
index a34d2f4..a97c3df 100644
--- a/client/src/View/Payment/Payment.hs
+++ b/client/src/View/Payment/Payment.hs
@@ -41,7 +41,7 @@ view input = do
R.dyn . R.ffor categories . Loadable.view $ \categories -> do
rec
- payments <- Reducer.reducer $ Reducer.In
+ paymentPage <- Reducer.reducer $ Reducer.In
{ Reducer._in_page = page
, Reducer._in_search = HeaderForm._out_search form
, Reducer._in_frequency = HeaderForm._out_frequency form
@@ -50,7 +50,7 @@ view input = do
, Reducer._in_deletePayment = deletePayment
}
- let eventFromResult :: forall a. (((), Table.Out t, Pages.Out t) -> Event t a) -> m (Event t a)
+ let eventFromResult :: forall a. ((Table.Out t, Pages.Out t) -> Event t a) -> m (Event t a)
eventFromResult op = ReflexUtil.flatten . fmap (Maybe.fromMaybe R.never . fmap op) $ result
let addPayment =
@@ -59,18 +59,18 @@ view input = do
, HeaderForm._out_addPayment form
]
- page <- eventFromResult $ Pages._out_newPage . (\(_, _, c) -> c)
- tableAddPayment <- eventFromResult $ Table._out_add . (\(_, b, _) -> b)
- editPayment <- eventFromResult $ Table._out_edit . (\(_, b, _) -> b)
- deletePayment <- eventFromResult $ Table._out_delete . (\(_, b, _) -> b)
+ page <- eventFromResult $ Pages._out_newPage . snd
+ tableAddPayment <- eventFromResult $ Table._out_add . fst
+ editPayment <- eventFromResult $ Table._out_edit . fst
+ deletePayment <- eventFromResult $ Table._out_delete . fst
form <- HeaderForm.view $ HeaderForm.In
{ HeaderForm._in_reset = () <$ addPayment
, HeaderForm._in_categories = categories
}
- result <- R.dyn . R.ffor payments $
- Loadable.view $ \(PaymentPage page frequency header payments count) -> do
+ result <- Loadable.view2 paymentPage $
+ \(PaymentPage page frequency header payments count) -> do
HeaderInfos.view $ HeaderInfos.In
{ HeaderInfos._in_users = _in_users input
@@ -94,7 +94,7 @@ view input = do
, Pages._in_page = page
}
- return ((), table, pages)
+ return (table, pages)
return ()
diff --git a/client/src/View/Payment/Reducer.hs b/client/src/View/Payment/Reducer.hs
index 0b6c041..d221ff0 100644
--- a/client/src/View/Payment/Reducer.hs
+++ b/client/src/View/Payment/Reducer.hs
@@ -13,9 +13,9 @@ import qualified Reflex.Dom as R
import Common.Model (Frequency (..), PaymentPage)
-import Loadable (Loadable (..))
-import qualified Loadable as Loadable
+import Loadable (Loadable2 (..))
import qualified Util.Ajax as AjaxUtil
+import qualified Util.Either as EitherUtil
perPage :: Int
perPage = 7
@@ -29,10 +29,6 @@ data In t a b c = In
, _in_deletePayment :: Event t c
}
-data Action
- = LoadPage
- | GetResult (Either Text PaymentPage)
-
data Params = Params
{ _params_page :: Int
, _params_search :: Text
@@ -48,7 +44,7 @@ data Msg
| ResetSearch
deriving Show
-reducer :: forall t m a b c. MonadWidget t m => In t a b c -> m (Dynamic t (Loadable PaymentPage))
+reducer :: forall t m a b c. MonadWidget t m => In t a b c -> m (Loadable2 t PaymentPage)
reducer input = do
postBuild <- R.getPostBuild
@@ -94,19 +90,19 @@ reducer input = do
getResult <- AjaxUtil.get (pageUrl <$> paramsEvent)
-
- R.foldDyn
- (\action _ -> case action of
- LoadPage -> Loading
- GetResult (Left err) -> Error err
- GetResult (Right payments) -> Loaded payments
- )
- Loading
+ isLoading <- R.holdDyn
+ True
(R.leftmost
- [ LoadPage <$ paramsEvent
- , GetResult <$> getResult
+ [ True <$ paramsEvent
+ , False <$ getResult
])
+ paymentPage <- R.holdDyn
+ Nothing
+ (fmap EitherUtil.eitherToMaybe getResult)
+
+ return $ Loadable2 isLoading paymentPage
+
where
pageUrl (Params page search frequency) =
"api/payments?page="