Skip to content

Commit 68b66d9

Browse files
committed
optsButtonLabel for Currency widget
1 parent 87cb52b commit 68b66d9

File tree

2 files changed

+32
-26
lines changed
  • ghcjs
    • delivery-calculator/src/App/Widgets
    • miso-functora/src/Functora/Miso/Widgets

2 files changed

+32
-26
lines changed

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,8 @@ menu st =
117117
Dialog.argsContent =
118118
Currency.selectCurrency
119119
Currency.defOpts
120-
{ Currency.optsExtraOnClick =
121-
(& #modelLoading .~ True),
122-
Currency.optsButtonViewer =
123-
mappend "Marketplace - "
124-
. Money.inspectCurrencyCode
125-
. Money.currencyInfoCode
120+
{ Currency.optsButtonLabel = Just "Marketplace currency",
121+
Currency.optsExtraOnClick = #modelLoading .~ True
126122
}
127123
Currency.Args
128124
{ Currency.argsModel = st,
@@ -137,12 +133,8 @@ menu st =
137133
}
138134
<> Currency.selectCurrency
139135
Currency.defOpts
140-
{ Currency.optsExtraOnClick =
141-
(& #modelLoading .~ True),
142-
Currency.optsButtonViewer =
143-
mappend "Merchant - "
144-
. Money.inspectCurrencyCode
145-
. Money.currencyInfoCode
136+
{ Currency.optsButtonLabel = Just "Merchant currency",
137+
Currency.optsExtraOnClick = #modelLoading .~ True
146138
}
147139
Currency.Args
148140
{ Currency.argsModel = st,

ghcjs/miso-functora/src/Functora/Miso/Widgets/Currency.hs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,25 @@ data Args model action = Args
2424
deriving stock (Generic)
2525

2626
data Opts model = Opts
27-
{ optsExtraOnClick :: model -> model,
28-
optsButtonViewer :: CurrencyInfo -> Unicode
27+
{ optsButtonLabel :: Maybe Unicode,
28+
optsButtonViewer :: CurrencyInfo -> Unicode,
29+
optsExtraOnClick :: model -> model
2930
}
3031
deriving stock (Generic)
3132

3233
defOpts :: Opts model
3334
defOpts =
3435
Opts
35-
{ optsExtraOnClick = id,
36-
optsButtonViewer = inspectCurrencyInfo
36+
{ optsButtonLabel = Nothing,
37+
optsButtonViewer = inspectCurrencyInfo,
38+
optsExtraOnClick = id
3739
}
3840

39-
selectCurrency :: Opts model -> Args model action -> [View action]
41+
selectCurrency ::
42+
forall model action.
43+
Opts model ->
44+
Args model action ->
45+
[View action]
4046
selectCurrency
4147
opts@Opts
4248
{ optsExtraOnClick = extraOnClick
@@ -47,13 +53,19 @@ selectCurrency
4753
argsAction = action,
4854
argsEmitter = emitter
4955
} =
50-
[ button_ [onClick open]
51-
. singleton
52-
. text
53-
. (opts ^. #optsButtonViewer)
54-
$ fromMaybe
55-
(CurrencyInfo (CurrencyCode "XXX") mempty)
56-
(st ^? cloneTraversal optic . #currencyOutput)
56+
[ maybe
57+
id
58+
(\x -> label_ mempty . (text x :) . singleton)
59+
(optsButtonLabel opts)
60+
$ input_
61+
[ type_ "button",
62+
onClick open,
63+
value_
64+
. optsButtonViewer opts
65+
$ fromMaybe
66+
(CurrencyInfo (CurrencyCode "XXX") mempty)
67+
(st ^? cloneTraversal optic . #currencyOutput)
68+
]
5769
]
5870
<> Dialog.dialog
5971
Dialog.defOpts
@@ -67,9 +79,11 @@ selectCurrency
6779
Field.argsAction = action,
6880
Field.argsEmitter = emitter
6981
}
70-
( Field.defOpts
82+
( Field.defOpts @model @action
7183
& #optsPlaceholder
72-
.~ "Search"
84+
.~ ("Search" :: Unicode)
85+
& #optsExtraAttributes
86+
.~ [autofocus_ True]
7387
)
7488
),
7589
Dialog.optsExtraOnClose =

0 commit comments

Comments
 (0)