Commit 33e78f2e authored by Joris's avatar Joris

Simplify page initialization

parent 602c52ac
......@@ -51,10 +51,9 @@ Executable client
Component.Link
Component.Modal
Component.Pages
Component.Table
Component.Select
Icon
Model.Loadable
Component.Table
Loadable
Model.Route
Util.Ajax
Util.Css
......@@ -67,6 +66,7 @@ Executable client
Util.WaitFor
View.App
View.Header
View.Icon
View.Income.Add
View.Income.Form
View.Income.Header
......
......@@ -12,7 +12,7 @@ import qualified Data.Text as T
import Reflex.Dom (Dynamic, Event, MonadWidget)
import qualified Reflex.Dom as R
import qualified Icon
import qualified View.Icon as Icon
data ButtonIn t m = ButtonIn
{ _buttonIn_class :: Dynamic t Text
......
......@@ -19,7 +19,7 @@ import qualified Reflex.Dom as R
import qualified Common.Util.Validation as ValidationUtil
import Component.Button (ButtonIn (..), ButtonOut (..))
import qualified Component.Button as Button
import qualified Icon
import qualified View.Icon as Icon
data InputIn a = InputIn
{ _inputIn_hasResetButton :: Bool
......
......@@ -11,8 +11,8 @@ import qualified Reflex.Dom as R
import Component.Button (ButtonIn (..), ButtonOut (..))
import qualified Component.Button as Button
import qualified Icon
import qualified Util.Reflex as ReflexUtil
import qualified View.Icon as Icon
data PagesIn t = PagesIn
{ _pagesIn_total :: Dynamic t Int
......
module Model.Loadable
module Loadable
( Loadable (..)
, fromEvent
, view
......
module Util.Ajax
( get
( getNow
, get
, post
, put
, delete
......@@ -21,6 +22,14 @@ import Reflex.Dom (Dynamic, Event, IsXhrPayload,
XhrResponseHeaders (..))
import qualified Reflex.Dom as R
import Loadable (Loadable)
import qualified Loadable
getNow :: forall t m a. (MonadWidget t m, FromJSON a) => Text -> m (Dynamic t (Loadable a))
getNow url = do
postBuild <- R.getPostBuild
get (R.tag (R.constant url) postBuild) >>= Loadable.fromEvent
get
:: forall t m a. (MonadWidget t m, FromJSON a)
=> Event t Text
......
......@@ -18,10 +18,10 @@ import qualified Common.Model as CM
import qualified Common.Msg as Msg
import Component (ButtonIn (..))
import qualified Component as Component
import qualified Icon
import Model.Route (Route (..))
import qualified Util.Css as CssUtil
import qualified Util.Reflex as ReflexUtil
import qualified View.Icon as Icon
data HeaderIn t = HeaderIn
{ _headerIn_initResult :: InitResult
......
module Icon
module View.Icon
( clone
, cross
, delete
......
......@@ -4,14 +4,15 @@ module View.Income.Income
, IncomeIn(..)
) where
import Data.Aeson (FromJSON)
import Prelude hiding (init)
import Reflex.Dom (Dynamic, MonadWidget)
import qualified Reflex.Dom as R
import Common.Model (Currency)
import Model.Loadable (Loadable (..))
import qualified Model.Loadable as Loadable
import Loadable (Loadable (..))
import qualified Loadable
import qualified Util.Ajax as AjaxUtil
import View.Income.Header (HeaderIn (..), HeaderOut (..))
import qualified View.Income.Header as Header
......@@ -26,17 +27,9 @@ data IncomeIn t = IncomeIn
init :: forall t m. MonadWidget t m => m (Dynamic t (Loadable Init))
init = do
postBuild <- R.getPostBuild
usersEvent <- AjaxUtil.get (R.tag (R.constant "api/users") postBuild)
users <- Loadable.fromEvent usersEvent
incomesEvent <- AjaxUtil.get (R.tag (R.constant "api/incomes") postBuild)
incomes <- Loadable.fromEvent incomesEvent
paymentsEvent <- AjaxUtil.get (R.tag (R.constant "api/payments") postBuild)
payments <- Loadable.fromEvent paymentsEvent
users <- AjaxUtil.getNow "api/users"
incomes <- AjaxUtil.getNow "api/incomes"
payments <- AjaxUtil.getNow "api/payments"
return $ do
us <- users
is <- incomes
......
......@@ -11,8 +11,8 @@ import qualified Reflex.Dom as R
import Component (ButtonIn (..), ButtonOut (..))
import qualified Component as Component
import qualified Icon
import qualified Util.Reflex as ReflexUtil
import qualified View.Icon as Icon
data PagesIn t = PagesIn
{ _pagesIn_total :: Dynamic t Int
......
......@@ -17,8 +17,8 @@ import Common.Model (Currency, Frequency, Income (..),
UserId)
import qualified Common.Util.Text as T
import Model.Loadable (Loadable (..))
import qualified Model.Loadable as Loadable
import Loadable (Loadable (..))
import qualified Loadable
import qualified Util.Ajax as AjaxUtil
import View.Payment.Header (HeaderIn (..), HeaderOut (..))
import qualified View.Payment.Header as Header
......@@ -30,23 +30,11 @@ import qualified View.Payment.Table as Table
init :: forall t m. MonadWidget t m => m (Dynamic t (Loadable Init))
init = do
postBuild <- R.getPostBuild
incomesEvent <- AjaxUtil.get (R.tag (R.constant "api/incomes") postBuild)
incomes <- Loadable.fromEvent incomesEvent
usersEvent <- AjaxUtil.get (R.tag (R.constant "api/users") postBuild)
users <- Loadable.fromEvent usersEvent
paymentsEvent <- AjaxUtil.get (R.tag (R.constant "api/payments") postBuild)
payments <- Loadable.fromEvent paymentsEvent
paymentCategoriesEvent <- AjaxUtil.get (R.tag (R.constant "api/paymentCategories") postBuild)
paymentCategories <- Loadable.fromEvent paymentCategoriesEvent
categoriesEvent <- AjaxUtil.get (R.tag (R.constant "api/categories") postBuild)
categories <- Loadable.fromEvent categoriesEvent
users <- AjaxUtil.getNow "api/users"
payments <- AjaxUtil.getNow "api/payments"
incomes <- AjaxUtil.getNow "api/incomes"
categories <- AjaxUtil.getNow "api/categories"
paymentCategories <- AjaxUtil.getNow "api/paymentCategories"
return $ do
us <- users
ps <- payments
......@@ -55,6 +43,7 @@ init = do
pcs <- paymentCategories
return $ Init <$> us <*> ps <*> is <*> cs <*> pcs
data PaymentIn t = PaymentIn
{ _paymentIn_currentUser :: UserId
, _paymentIn_currency :: Currency
......
......@@ -28,8 +28,8 @@ import qualified View.Payment.Delete as Delete
import qualified View.Payment.Edit as Edit
import View.Payment.Init (Init (..))
import qualified Icon
import qualified Util.Reflex as ReflexUtil
import qualified View.Icon as Icon
data TableIn t = TableIn
{ _tableIn_init :: Init
......
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