Skip to content

Commit 982ea09

Browse files
committed
better fav
1 parent a13f697 commit 982ea09

File tree

2 files changed

+63
-36
lines changed

2 files changed

+63
-36
lines changed

ghcjs/currency-converter/src/App/Widgets/Fav.hs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import qualified App.Widgets.Cell as Cell
99
import qualified App.Widgets.Field as Field
1010
import App.Widgets.Templates
1111
import qualified Data.Map as Map
12+
import qualified Data.Text as T
1213
import Functora.Miso.Prelude
1314
import qualified Material.Button as Button
1415
import qualified Material.Dialog as Dialog
@@ -39,7 +40,14 @@ fav st =
3940
)
4041
( Field.defOpts
4142
& #optsPlaceholder
42-
.~ ("Name - " <> makeFavName st)
43+
.~ ( let name = makeFavName st
44+
in "Name"
45+
<> ( if name == mempty
46+
then mempty
47+
else " - "
48+
)
49+
<> name
50+
)
4351
),
4452
Cell.smallCell
4553
$ Button.raised
@@ -94,7 +102,11 @@ fav st =
94102
makeFavName nextSt
95103
in nextSt
96104
& ( Misc.textPopupPure
97-
$ "Saved "
105+
$ "Saved"
106+
<> ( if nextFavName == mempty
107+
then mempty
108+
else " "
109+
)
98110
<> nextFavName
99111
<> "!"
100112
)
@@ -117,31 +129,16 @@ fav st =
117129

118130
makeFavName :: Model -> MisoString
119131
makeFavName st =
120-
preFavName
121-
<> ( if preFavName == mempty
122-
then mempty
123-
else " "
124-
)
125-
<> getCode #stDocTopMoney
126-
<> "/"
127-
<> getCode #stDocBottomMoney
132+
toMisoString
133+
. T.toUpper
134+
$ fromMisoString preFavName
128135
where
129136
preFavName =
130137
st
131138
^. #modelState
132139
. #stDoc
133140
. #stDocPreFavName
134141
. #fieldOutput
135-
getCode optic =
136-
st
137-
^. #modelState
138-
. #stDoc
139-
. cloneLens optic
140-
. #moneyCurrency
141-
. #currencyOutput
142-
. #currencyInfoCode
143-
. #unCurrencyCode
144-
. to toMisoString
145142

146143
favItems :: Model -> [View Action]
147144
favItems st =

ghcjs/currency-converter/src/App/Widgets/Menu.hs

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ menu st =
6060
$ IconButton.iconButton
6161
( IconButton.config
6262
& IconButton.setOnClick
63-
( pureUpdate 0
64-
$ (& #modelFav .~ Opened)
65-
. ( &
66-
#modelState
67-
. #stDoc
68-
. #stDocPreFavName
69-
. #fieldInput
70-
. #uniqueValue
71-
.~ mempty
72-
)
63+
( pureUpdate 0 $ \next ->
64+
next
65+
& #modelFav
66+
.~ Opened
67+
& #modelState
68+
. #stDoc
69+
. #stDocPreFavName
70+
. #fieldInput
71+
. #uniqueValue
72+
.~ defFavName next
7373
)
7474
& IconButton.setAttributes
7575
[ TopAppBar.actionItem,
@@ -150,6 +150,7 @@ menu st =
150150
Cell.smallCell
151151
$ Button.raised
152152
( Button.config
153+
& Button.setDisabled disabled
153154
& Button.setOnClick
154155
( Misc.newFieldPairAction
155156
$ #modelState
@@ -169,6 +170,7 @@ menu st =
169170
in Cell.mediumCell
170171
$ Select.outlined
171172
( Select.config
173+
& Select.setDisabled disabled
172174
& Select.setLabel
173175
( Just "Exchange rate"
174176
)
@@ -211,6 +213,8 @@ menu st =
211213
( #modelState . #stPre
212214
)
213215
( Field.defOpts
216+
& #optsDisabled
217+
.~ disabled
214218
& #optsPlaceholder
215219
.~ ( "Preview - "
216220
<> ( st
@@ -240,16 +244,22 @@ menu st =
240244
. #stIkm
241245
)
242246
( Field.defOpts
247+
& #optsDisabled
248+
.~ disabled
243249
& #optsFilledOrOutlined
244250
.~ Outlined
245251
)
246252
]
247-
<> FieldPairs.fieldPairs
248-
st
249-
( #modelState
250-
. #stDoc
251-
. #stDocFieldPairs
252-
)
253+
<> ( if disabled
254+
then mempty
255+
else
256+
FieldPairs.fieldPairs
257+
st
258+
( #modelState
259+
. #stDoc
260+
. #stDocFieldPairs
261+
)
262+
)
253263
<> [ Cell.bigCell
254264
$ Button.raised
255265
( Button.config
@@ -273,6 +283,8 @@ menu st =
273283
. (& #modelState . #stScreen .~ next)
274284
sc =
275285
st ^. #modelState . #stScreen
286+
disabled =
287+
isJust $ st ^. #modelState . #stCpt
276288
navItemLeft x =
277289
div_
278290
[ TopAppBar.title,
@@ -293,3 +305,21 @@ menu st =
293305
]
294306
[ x
295307
]
308+
309+
defFavName :: Model -> MisoString
310+
defFavName st =
311+
if isJust (st ^. #modelState . #stCpt)
312+
|| (st ^. #modelState . #stIkm . #fieldOutput /= mempty)
313+
then mempty
314+
else getCode #stDocTopMoney <> "/" <> getCode #stDocBottomMoney
315+
where
316+
getCode optic =
317+
st
318+
^. #modelState
319+
. #stDoc
320+
. cloneLens optic
321+
. #moneyCurrency
322+
. #currencyOutput
323+
. #currencyInfoCode
324+
. #unCurrencyCode
325+
. to toMisoString

0 commit comments

Comments
 (0)