Skip to content

Commit 943aec3

Browse files
committed
delivery calculator wip
1 parent 401373a commit 943aec3

File tree

3 files changed

+84
-29
lines changed

3 files changed

+84
-29
lines changed

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

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module App.Types
1111
unQrCode,
1212
unShareUri,
1313
stUri,
14+
stTeleUri,
1415
setScreenPure,
1516
setScreenAction,
1617
vsn,
@@ -62,10 +63,10 @@ data Action
6263

6364
data St f = St
6465
{ stAssets :: [Asset f],
65-
stPayments :: [Money f],
66-
stFeePercent :: Field Rational f,
66+
stPayment :: Money f,
67+
stMerchantTele :: Field Unicode f,
68+
stMerchantFeePercent :: Field Rational f,
6769
stDefAssetCurrency :: Currency f,
68-
stDefPaymentCurrency :: Currency f,
6970
stFavName :: Field Unicode f,
7071
stPreview :: Field Unicode f,
7172
stScreen :: Screen
@@ -89,19 +90,20 @@ deriving via GenericType (St Identity) instance Binary (St Identity)
8990
newSt :: (MonadIO m) => m (St Unique)
9091
newSt = do
9192
fee <- newRatioField 2
92-
assetCur <- newCurrency cny
93-
paymentCur <- newCurrency rub
93+
payment <- newMoney 0 rub
94+
defAssetCur <- newCurrency cny
9495
fav <- newTextField mempty
95-
pre <- newTextField mempty
96+
pre <- newTextField "Delivery Calculator"
97+
tele <- newTextField "Functora"
9698
pure
9799
St
98100
{ stAssets = mempty,
99-
stPayments = mempty,
100-
stFeePercent = fee,
101-
stDefAssetCurrency = assetCur,
102-
stDefPaymentCurrency = paymentCur,
101+
stPayment = payment,
102+
stMerchantTele = tele,
103+
stMerchantFeePercent = fee,
104+
stDefAssetCurrency = defAssetCur,
103105
stFavName = fav,
104-
stPreview = pre,
106+
stPreview = pre & #fieldType .~ FieldTypeTitle,
105107
stScreen = Main
106108
}
107109

@@ -166,6 +168,22 @@ stQuery st = do
166168
. B64URL.encode
167169
. from @BL.ByteString @ByteString
168170

171+
stTeleUri :: (MonadThrow m) => Model -> m URI
172+
stTeleUri st = do
173+
base <- URI.mkURI "https://t.me"
174+
user <- URI.mkPathPiece $ st ^. #modelState . #stMerchantTele . #fieldOutput
175+
link <- stUri st
176+
key <- URI.mkQueryKey "text"
177+
val <-
178+
URI.mkQueryValue
179+
$ "Hello, I have a question about the delivery of the following items: "
180+
<> URI.render link
181+
pure
182+
$ base
183+
{ URI.uriPath = Just (False, [user]),
184+
URI.uriQuery = [URI.QueryParam key val]
185+
}
186+
169187
unShareUri ::
170188
( MonadIO m,
171189
MonadThrow m

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,37 @@ screenWidget st@Model {modelState = St {stScreen = QrCode sc}} =
8080
"Open"
8181
]
8282
]
83-
screenWidget Model {modelState = St {stScreen = Main}} =
84-
mempty
8583
screenWidget st@Model {modelState = St {stScreen = Donate}} =
8684
FieldPairs.fieldPairsViewer
8785
FieldPairs.Args
8886
{ FieldPairs.argsModel = st,
8987
FieldPairs.argsOptic = #modelDonateViewer,
9088
FieldPairs.argsAction = PushUpdate . Instant
9189
}
90+
screenWidget Model {modelState = St {stScreen = Main}} =
91+
[ Grid.mediumCell
92+
[ Button.raised
93+
( Button.config
94+
& Button.setIcon (Just "add_box")
95+
& Button.setAttributes [Css.fullWidth]
96+
& Button.setOnClick Noop
97+
)
98+
"Add item"
99+
],
100+
Grid.mediumCell
101+
[ Button.raised
102+
( Button.config
103+
& Button.setIcon (Just "send")
104+
& Button.setAttributes [Css.fullWidth]
105+
& Button.setOnClick
106+
( PushUpdate
107+
. Instant
108+
$ \next -> flip Jsm.openBrowserPage next =<< stTeleUri next
109+
)
110+
)
111+
"Order via Telegram"
112+
]
113+
]
92114

93115
pasteWidget ::
94116
Unicode ->

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

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,37 @@ menu st =
147147
}
148148
( Field.defOpts @Model @Action
149149
& #optsPlaceholder
150-
.~ ( "Preview - "
151-
<> ( st
152-
^. #modelState
153-
. #stPreview
154-
. #fieldType
155-
. to userFieldType
156-
)
157-
)
158-
& #optsLeadingWidget
159-
.~ Just
160-
( Field.ModalWidget
161-
$ Field.ModalMiniWidget
162-
( #modelState
163-
. #stPreview
164-
)
165-
)
150+
.~ ("QR title" :: Unicode)
151+
& #optsFilledOrOutlined
152+
.~ Outlined
153+
)
154+
],
155+
Grid.mediumCell
156+
[ Field.ratioField
157+
Field.Args
158+
{ Field.argsModel = st,
159+
Field.argsOptic =
160+
#modelState . #stMerchantFeePercent,
161+
Field.argsAction =
162+
PushUpdate . Instant
163+
}
164+
( Field.defOpts
165+
& #optsPlaceholder
166+
.~ ("Merchant fee %" :: Unicode)
167+
& #optsFilledOrOutlined
168+
.~ Outlined
169+
)
170+
],
171+
Grid.mediumCell
172+
[ Field.textField
173+
Field.Args
174+
{ Field.argsModel = st,
175+
Field.argsOptic = #modelState . #stMerchantTele,
176+
Field.argsAction = PushUpdate . Instant
177+
}
178+
( Field.defOpts
179+
& #optsPlaceholder
180+
.~ ("Merchant telegram" :: Unicode)
166181
& #optsFilledOrOutlined
167182
.~ Outlined
168183
)

0 commit comments

Comments
 (0)