Skip to content

Commit 3ef40ac

Browse files
committed
image file input wip
1 parent b3a8b7e commit 3ef40ac

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,22 @@ newAsset = do
177177
newFieldPair "Price" $ DynamicFieldNumber 10
178178
qty <-
179179
newFieldPair "Quantity" $ DynamicFieldNumber 1
180+
comment <-
181+
newFieldPair "Comment" $ DynamicFieldText mempty
180182
pure
181183
Asset
182-
{ assetFieldPairs = [link, photo, price, qty],
184+
{ assetFieldPairs =
185+
[ required link,
186+
required photo,
187+
required price,
188+
required qty,
189+
comment
190+
],
183191
assetModalState = Opened
184192
}
193+
where
194+
required :: FieldPair DynamicField Unique -> FieldPair DynamicField Unique
195+
required = #fieldPairValue . #fieldRequired .~ True
185196

186197
newFieldPair ::
187198
( MonadIO m

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ menu st =
6767
[Dialog.optsIcon Dialog.defOpts Icon.IconShare]
6868
)
6969
:
70+
),
71+
Dialog.optsFooterRight =
72+
( ( button_
73+
[shareOnClick]
74+
[ Dialog.optsIcon Dialog.defOpts Icon.IconShare,
75+
text " Share"
76+
]
77+
)
78+
:
7079
)
7180
}
7281
)

ghcjs/miso-functora/src/Functora/Miso/Types.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ data Field a f = Field
122122
fieldInput :: f Unicode,
123123
fieldOutput :: a,
124124
fieldModalState :: OpenedOrClosed,
125+
fieldRequired :: Bool,
125126
fieldOpts :: FieldOpts
126127
}
127128
deriving stock (Generic)
@@ -175,6 +176,7 @@ newField typ output newInput = do
175176
fieldInput = input,
176177
fieldOutput = output,
177178
fieldModalState = Closed,
179+
fieldRequired = False,
178180
fieldOpts = defFieldOpts
179181
}
180182

@@ -185,6 +187,7 @@ newFieldId typ viewer output =
185187
fieldInput = Identity $ viewer output,
186188
fieldOutput = output,
187189
fieldModalState = Closed,
190+
fieldRequired = False,
188191
fieldOpts = defFieldOpts
189192
}
190193

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,17 @@ field full@Full {fullArgs = args, fullParser = parser, fullViewer = viewer} opts
162162
if null src
163163
then mempty
164164
else
165-
[ img_
165+
[ input_
166+
$ catMaybes
167+
[ Just $ type_ "file",
168+
Just $ accept_ "image/*",
169+
Just $ onInput onInputAction,
170+
fmap required_
171+
$ st
172+
^? cloneTraversal optic
173+
. #fieldRequired
174+
],
175+
img_
166176
( loading_ "lazy"
167177
: src_ src
168178
: optsExtraAttributes opts
@@ -174,6 +184,10 @@ field full@Full {fullArgs = args, fullParser = parser, fullViewer = viewer} opts
174184
. input_
175185
$ ( catMaybes
176186
[ Just . type_ $ htmlFieldType typ,
187+
fmap required_
188+
$ st
189+
^? cloneTraversal optic
190+
. #fieldRequired,
177191
fmap
178192
(textProp "defaultValue")
179193
( st

0 commit comments

Comments
 (0)