aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/client.cabal6
-rw-r--r--client/src/Component/Button.hs2
-rw-r--r--client/src/Component/Input.hs2
-rw-r--r--client/src/Component/Pages.hs2
-rw-r--r--client/src/Loadable.hs (renamed from client/src/Model/Loadable.hs)2
-rw-r--r--client/src/Util/Ajax.hs11
-rw-r--r--client/src/View/Header.hs2
-rw-r--r--client/src/View/Icon.hs (renamed from client/src/Icon.hs)2
-rw-r--r--client/src/View/Income/Income.hs19
-rw-r--r--client/src/View/Payment/Pages.hs2
-rw-r--r--client/src/View/Payment/Payment.hs27
-rw-r--r--client/src/View/Payment/Table.hs2
12 files changed, 35 insertions, 44 deletions
diff --git a/client/client.cabal b/client/client.cabal
index 9a0d24e..9e0a47e 100644
--- a/client/client.cabal
+++ b/client/client.cabal
@@ -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
diff --git a/client/src/Component/Button.hs b/client/src/Component/Button.hs
index 46c0afa..b1175d7 100644
--- a/client/src/Component/Button.hs
+++ b/client/src/Component/Button.hs
@@ -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
diff --git a/client/src/Component/Input.hs b/client/src/Component/Input.hs
index 0c84754..9ab4d58 100644
--- a/client/src/Component/Input.hs
+++ b/client/src/Component/Input.hs
@@ -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
diff --git a/client/src/Component/Pages.hs b/client/src/Component/Pages.hs
index 5611cb7..7843ef6 100644
--- a/client/src/Component/Pages.hs
+++ b/client/src/Component/Pages.hs
@@ -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
diff --git a/client/src/Model/Loadable.hs b/client/src/Loadable.hs
index 3076b46..8714a4d 100644
--- a/client/src/Model/Loadable.hs
+++ b/client/src/Loadable.hs
@@ -1,4 +1,4 @@
-module Model.Loadable
+module Loadable
( Loadable (..)
, fromEvent
, view
diff --git a/client/src/Util/Ajax.hs b/client/src/Util/Ajax.hs
index 9cd5105..47f4f3c 100644
--- a/client/src/Util/Ajax.hs
+++ b/client/src/Util/Ajax.hs
@@ -1,5 +1,6 @@
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
diff --git a/client/src/View/Header.hs b/client/src/View/Header.hs
index bd69e47..68329eb 100644
--- a/client/src/View/Header.hs
+++ b/client/src/View/Header.hs
@@ -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
diff --git a/client/src/Icon.hs b/client/src/View/Icon.hs
index 1a45933..cc2ef3f 100644
--- a/client/src/Icon.hs
+++ b/client/src/View/Icon.hs
@@ -1,4 +1,4 @@
-module Icon
+module View.Icon
( clone
, cross
, delete
diff --git a/client/src/View/Income/Income.hs b/client/src/View/Income/Income.hs
index 91682a0..18ebe7c 100644
--- a/client/src/View/Income/Income.hs
+++ b/client/src/View/Income/Income.hs
@@ -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
diff --git a/client/src/View/Payment/Pages.hs b/client/src/View/Payment/Pages.hs
index 9247143..5681935 100644
--- a/client/src/View/Payment/Pages.hs
+++ b/client/src/View/Payment/Pages.hs
@@ -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
diff --git a/client/src/View/Payment/Payment.hs b/client/src/View/Payment/Payment.hs
index ec350e2..5f0d03c 100644
--- a/client/src/View/Payment/Payment.hs
+++ b/client/src/View/Payment/Payment.hs
@@ -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
diff --git a/client/src/View/Payment/Table.hs b/client/src/View/Payment/Table.hs
index 5ffa037..3a0a4bf 100644
--- a/client/src/View/Payment/Table.hs
+++ b/client/src/View/Payment/Table.hs
@@ -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