diff options
author | Joris | 2019-10-20 09:51:52 +0200 |
---|---|---|
committer | Joris | 2019-10-20 09:51:52 +0200 |
commit | 6e9e34e92a244ab6c38d135d46f9f5bb01391906 (patch) | |
tree | 18474c001278f70d401b705169730a32848af83c /client/src/View/Income/Header.hs | |
parent | 0b40b6b5583b5c437f83e61bf8913f2b4c447b24 (diff) |
Move income header and income table views into separate components
Diffstat (limited to 'client/src/View/Income/Header.hs')
-rw-r--r-- | client/src/View/Income/Header.hs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/client/src/View/Income/Header.hs b/client/src/View/Income/Header.hs new file mode 100644 index 0000000..b7170c9 --- /dev/null +++ b/client/src/View/Income/Header.hs @@ -0,0 +1,60 @@ +module View.Income.Header + ( view + , HeaderIn(..) + ) where + +import Control.Monad.IO.Class (liftIO) +import qualified Data.Maybe as Maybe +import qualified Data.Text as T +import qualified Data.Time.Clock as Clock +import Reflex.Dom (MonadWidget) +import qualified Reflex.Dom as R + +import Common.Model (Income (..), Init (..), User (..)) +import qualified Common.Model as CM +import qualified Common.Msg as Msg +import qualified Common.View.Format as Format +import qualified Util.Date as DateUtil + +data HeaderIn = HeaderIn + { _headerIn_init :: Init + } + +view :: forall t m. MonadWidget t m => HeaderIn -> m () +view headerIn = + R.divClass "withMargin" $ do + + currentTime <- liftIO Clock.getCurrentTime + + Maybe.fromMaybe R.blank $ + flip fmap useIncomesFrom $ \since -> + R.el "div" $ do + + R.el "h1" $ do + day <- liftIO $ DateUtil.utcToLocalDay since + R.text $ Msg.get (Msg.Income_CumulativeSince (Format.longDay day)) + + R.el "ul" $ + flip mapM_ (_init_users init) $ \user -> + R.el "li" $ + R.text $ do + let incomes = filter ((==) (_user_id user) . _income_userId) (_init_incomes init) + T.intercalate " " + [ _user_name user + , "−" + , Format.price (_init_currency init) $ + CM.cumulativeIncomesSince currentTime since incomes + ] + + R.divClass "titleButton" $ + R.el "h1" $ + R.text $ + Msg.get Msg.Income_MonthlyNet + + where + init = _headerIn_init headerIn + + useIncomesFrom = CM.useIncomesFrom + (map _user_id $_init_users init) + (_init_incomes init) + (_init_payments init) |