aboutsummaryrefslogtreecommitdiff
path: root/client/src/View/Payment/Pages.hs
blob: cf3e1151e397d9ef6eeda3d22163279336ca4769 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecursiveDo       #-}

module View.Payment.Pages
  ( widget
  , PagesIn(..)
  , PagesOut(..)
  ) where

import qualified Data.Text    as T
import           Reflex.Dom   (Event, Dynamic, MonadWidget)
import qualified Reflex.Dom   as R

import           Common.Model (Payment (..))

import           Component    (ButtonIn (..), ButtonOut (..))
import qualified Component    as Component
import qualified Icon

data PagesIn = PagesIn
  { _pagesIn_payments :: [Payment]
  }

data PagesOut t = PagesOut
  { _pagesOut_currentPage :: Dynamic t Int
  }

widget :: forall t m. MonadWidget t m => PagesIn -> m (PagesOut t)
widget _ = do
  currentPage <- R.divClass "pages" $ do
    a <- page 1 Icon.doubleLeftBar
    b <- page 1 Icon.doubleLeft
    c <- page 1 (R.text . T.pack . show $ (1 :: Integer))
    d <- page 2 (R.text . T.pack . show $ (2 :: Integer))
    e <- page 3 (R.text . T.pack . show $ (3 :: Integer))
    f <- page 4 (R.text . T.pack . show $ (4 :: Integer))
    g <- page 5 (R.text . T.pack . show $ (5 :: Integer))
    h <- page 5 Icon.doubleRight
    i <- page 5 Icon.doubleRightBar
    R.holdDyn 1 $ R.leftmost [ a, b, c, d, e, f, g, h, i ]
  return $ PagesOut
    { _pagesOut_currentPage = currentPage
    }

page :: forall t m. MonadWidget t m => Int -> m () -> m (Event t Int)
page n content =
  ((fmap (const n)) . _buttonOut_clic) <$> (Component.button $ ButtonIn
    { _buttonIn_class   = "page"
    , _buttonIn_content = content
    , _buttonIn_waiting = R.never
    })