Skip to content

Commit 8775227

Browse files
committed
WIP
1 parent 2e7235a commit 8775227

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

ghcjs/delivery-calculator/src/App/Types.hs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ module App.Types
66
Action (..),
77
St (..),
88
newSt,
9+
Asset (..),
10+
newAsset,
911
Screen (..),
1012
isQrCode,
1113
unQrCode,
@@ -34,7 +36,7 @@ import Data.Functor.Barbie
3436
import qualified Data.Version as Version
3537
import Functora.Cfg
3638
import Functora.Miso.Prelude
37-
import Functora.Miso.Types as X hiding (Asset (..))
39+
import Functora.Miso.Types as X hiding (Asset (..), newAsset)
3840
import Functora.Money hiding (Currency, Money, Text)
3941
import qualified Functora.Prelude as Prelude
4042
import qualified Functora.Rates as Rates
@@ -121,10 +123,11 @@ newSt = do
121123
}
122124

123125
data Asset f = Asset
124-
{ assetLink :: Field URI f,
125-
assetPhoto :: Field URI f,
126+
{ assetLink :: Field Unicode f,
127+
assetPhoto :: Field Unicode f,
126128
assetPrice :: Field Rational f,
127-
assetQty :: Field Rational f
129+
assetQty :: Field Rational f,
130+
assetOoc :: OpenedOrClosed
128131
}
129132
deriving stock (Generic)
130133

@@ -142,6 +145,21 @@ instance TraversableB Asset
142145

143146
deriving via GenericType (Asset Identity) instance Binary (Asset Identity)
144147

148+
newAsset :: (MonadIO m) => m (Asset Unique)
149+
newAsset = do
150+
link <- newTextField mempty
151+
photo <- newTextField mempty
152+
price <- newRatioField 0
153+
qty <- newRatioField 1
154+
pure
155+
Asset
156+
{ assetLink = link,
157+
assetPhoto = photo,
158+
assetPrice = price,
159+
assetQty = qty,
160+
assetOoc = Opened
161+
}
162+
145163
data Screen
146164
= Main
147165
| Donate

ghcjs/delivery-calculator/src/App/Widgets/Main.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ screenWidget Model {modelState = St {stScreen = Main}} =
107107
( Button.config
108108
& Button.setIcon (Just "add_box")
109109
& Button.setAttributes [Css.fullWidth]
110-
& Button.setOnClick Noop
110+
& Button.setOnClick
111+
( PushUpdate . Instant $ \st -> do
112+
asset <- newAsset
113+
pure $ st & #modelState . #stAssets %~ flip snoc asset
114+
)
111115
)
112116
"Add item"
113117
],

0 commit comments

Comments
 (0)