Skip to content

Commit 472fe26

Browse files
committed
wip
1 parent f0e6768 commit 472fe26

File tree

5 files changed

+72
-57
lines changed

5 files changed

+72
-57
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ newSt = do
145145
}
146146

147147
data Asset f = Asset
148-
{ assetFieldPairs :: [FieldPair DynamicField f],
148+
{ assetUid :: Uid,
149+
assetFieldPairs :: [FieldPair DynamicField f],
149150
assetModalState :: OpenedOrClosed,
150151
assetMustVerify :: Bool
151152
}
@@ -167,6 +168,7 @@ deriving via GenericType (Asset Identity) instance Binary (Asset Identity)
167168

168169
newAsset :: (MonadIO m, MonadThrow m) => m (Asset Unique)
169170
newAsset = do
171+
uid <- newUid
170172
link <-
171173
newFieldPair "Link"
172174
$ DynamicFieldText mempty
@@ -204,7 +206,8 @@ newAsset = do
204206
newFieldPair "Comment" $ DynamicFieldText mempty
205207
pure
206208
Asset
207-
{ assetFieldPairs =
209+
{ assetUid = uid,
210+
assetFieldPairs =
208211
[ required link,
209212
required photo,
210213
required qty,

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

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,58 +19,70 @@ assetsViewer st = do
1919

2020
assetViewer :: Model -> Int -> [View Action]
2121
assetViewer st idx =
22-
[ fieldset_ mempty
23-
$ ( legend_
24-
mempty
25-
[ text title,
26-
text " ",
27-
button_
28-
[ onClick
29-
. PushUpdate
30-
. PureUpdate
31-
$ cloneTraversal modalOptic
32-
.~ Opened
33-
]
34-
[ icon Icon.IconEdit,
35-
text " Edit"
36-
]
37-
]
22+
[ keyed uid
23+
. fieldset_ mempty
24+
$ ( ( legend_
25+
mempty
26+
[ text title,
27+
text " ",
28+
button_
29+
[ onClick
30+
. PushUpdate
31+
. PureUpdate
32+
$ cloneTraversal modalOptic
33+
.~ Opened
34+
]
35+
[ icon Icon.IconEdit,
36+
text " Edit"
37+
]
38+
]
39+
)
40+
: FieldPairs.fieldPairsViewer fieldPairsOpts args
3841
)
39-
: FieldPairs.fieldPairsViewer fieldPairsOpts args
42+
<> ( Dialog.dialog
43+
Dialog.defOpts
44+
{ Dialog.optsTitle = Just title,
45+
Dialog.optsExtraOnClose = saveUpdate,
46+
Dialog.optsHeaderRight =
47+
const
48+
[ button_
49+
[type_ "reset", onClick removeAction]
50+
[icon Icon.IconDelete],
51+
button_
52+
[type_ "submit", onClick saveAction]
53+
[icon Icon.IconSave]
54+
],
55+
Dialog.optsFooterRight =
56+
const
57+
[ button_
58+
[type_ "reset", onClick removeAction]
59+
[icon Icon.IconDelete, text " Remove"],
60+
button_
61+
[type_ "submit", onClick saveAction]
62+
[icon Icon.IconSave, text " Save"]
63+
]
64+
}
65+
Dialog.Args
66+
{ Dialog.argsModel = st,
67+
Dialog.argsOptic = modalOptic,
68+
Dialog.argsAction = PushUpdate,
69+
Dialog.argsContent =
70+
failures False
71+
<> FieldPairs.fieldPairsEditor args fieldPairsOpts
72+
}
73+
)
4074
]
41-
<> ( Dialog.dialog
42-
Dialog.defOpts
43-
{ Dialog.optsTitle = Just title,
44-
Dialog.optsExtraOnClose = saveUpdate,
45-
Dialog.optsHeaderRight =
46-
const
47-
[ button_
48-
[type_ "reset", onClick removeAction]
49-
[icon Icon.IconDelete],
50-
button_
51-
[type_ "submit", onClick saveAction]
52-
[icon Icon.IconSave]
53-
],
54-
Dialog.optsFooterRight =
55-
const
56-
[ button_
57-
[type_ "reset", onClick removeAction]
58-
[icon Icon.IconDelete, text " Remove"],
59-
button_
60-
[type_ "submit", onClick saveAction]
61-
[icon Icon.IconSave, text " Save"]
62-
]
63-
}
64-
Dialog.Args
65-
{ Dialog.argsModel = st,
66-
Dialog.argsOptic = modalOptic,
67-
Dialog.argsAction = PushUpdate,
68-
Dialog.argsContent =
69-
failures False
70-
<> FieldPairs.fieldPairsEditor args fieldPairsOpts
71-
}
72-
)
7375
where
76+
uid =
77+
decodeUtf8
78+
. unTagged
79+
. htmlUid
80+
. fromMaybe nilUid
81+
$ st
82+
^? #modelState
83+
. #stAssets
84+
. ix idx
85+
. #assetUid
7486
args =
7587
FieldPairs.Args
7688
{ FieldPairs.argsModel = st,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ totalViewer st =
164164
then mempty
165165
else
166166
singleton
167-
$ fieldset_ mempty
167+
. keyed "total"
168+
. fieldset_ mempty
168169
$ (legend_ mempty [text "Total"])
169170
: FieldPairs.fieldPairsViewer
170171
FieldPairs.defOpts

ghcjs/delivery-calculator/src/Main.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,13 @@ updateModel (EvalUpdate f) st = do
204204
$ #modelUriViewer
205205
%~ mergeFieldPairs
206206
[ uriViewer
207-
& #fieldPairValue
208-
. #fieldOpts
209-
. #fieldOptsQrState
210-
.~ Just Opened
211207
& #fieldPairValue
212208
. #fieldOpts
213209
. #fieldOptsAllowCopy
214210
.~ True
211+
& #fieldPairValue
212+
. #fieldType
213+
.~ FieldTypeQrCode
215214
],
216215
do
217216
--

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ genericFieldViewer opts0 args widget =
810810
. _Just
811811
%~ nextEnum
812812
)
813-
<> ( if isNothing $ opts ^. #fieldOptsQrState
813+
<> ( if typ == FieldTypeQrCode || isNothing (opts ^. #fieldOptsQrState)
814814
then mempty
815815
else
816816
pure

0 commit comments

Comments
 (0)