aboutsummaryrefslogtreecommitdiff
path: root/client/src/View/Payment/Reducer.hs
diff options
context:
space:
mode:
authorJoris2019-11-24 16:19:53 +0100
committerJoris2019-11-24 16:19:53 +0100
commit54628c70cb33de5e4309c35b9f6b57bbe9f7a07b (patch)
tree57e331cadfdf81b5598d21f76302f5269fd58344 /client/src/View/Payment/Reducer.hs
parent3c67fcf1d524811a18f0c4db3ef6eed1270b9a12 (diff)
downloadbudget-54628c70cb33de5e4309c35b9f6b57bbe9f7a07b.tar.gz
budget-54628c70cb33de5e4309c35b9f6b57bbe9f7a07b.tar.bz2
budget-54628c70cb33de5e4309c35b9f6b57bbe9f7a07b.zip
Compute cumulative income with a DB query
Diffstat (limited to 'client/src/View/Payment/Reducer.hs')
-rw-r--r--client/src/View/Payment/Reducer.hs30
1 files changed, 13 insertions, 17 deletions
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="