Skip to content

Commit cc89b60

Browse files
committed
wip
1 parent d174c35 commit cc89b60

File tree

2 files changed

+28
-83
lines changed

2 files changed

+28
-83
lines changed

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ newDynamicField output =
213213
( case output of
214214
DynamicFieldText {} -> FieldTypeText
215215
DynamicFieldNumber {} -> FieldTypeNumber
216-
DynamicFieldRfc2397 {} -> FieldTypeImage
217216
)
218217
output
219218
inspectDynamicField
@@ -224,7 +223,6 @@ newDynamicFieldId output =
224223
( case output of
225224
DynamicFieldText {} -> FieldTypeText
226225
DynamicFieldNumber {} -> FieldTypeNumber
227-
DynamicFieldRfc2397 {} -> FieldTypeImage
228226
)
229227
inspectDynamicField
230228
output
@@ -239,7 +237,6 @@ newDynamicTitleField =
239237
data DynamicField
240238
= DynamicFieldText Unicode
241239
| DynamicFieldNumber Rational
242-
| DynamicFieldRfc2397 (Maybe Unicode) Rfc2397
243240
deriving stock (Eq, Ord, Show, Data, Generic)
244241
deriving (Binary) via GenericType DynamicField
245242

@@ -256,20 +253,12 @@ parseDynamic value str =
256253
case value ^. #fieldType of
257254
FieldTypeNumber -> DynamicFieldNumber <$> parseRatio str
258255
FieldTypePercent -> DynamicFieldNumber <$> parseRatio str
259-
FieldTypeImage -> do
260-
let mVal = decodeRfc2397 str
261-
let mRef = case value ^. #fieldOutput of
262-
DynamicFieldRfc2397 ref val | mVal == Just val -> ref
263-
_ -> Nothing
264-
fmap (DynamicFieldRfc2397 mRef) mVal <|> Just (DynamicFieldText str)
265-
_ ->
266-
Just $ DynamicFieldText str
256+
_ -> Just $ DynamicFieldText str
267257

268258
inspectDynamicField :: DynamicField -> Unicode
269259
inspectDynamicField = \case
270260
DynamicFieldText x -> x
271261
DynamicFieldNumber x -> inspectRatioDef x
272-
DynamicFieldRfc2397 _ x -> encodeRfc2397 x
273262

274263
data FieldType
275264
= -- Rational

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

Lines changed: 27 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import qualified Functora.Miso.Widgets.Qr as Qr
2727
import qualified Functora.Miso.Widgets.Select as Select
2828
import qualified Language.Javascript.JSaddle as JS
2929
import qualified Miso.String as MS
30-
import Type.Reflection
3130

3231
data Args model action t f = Args
3332
{ argsModel :: model,
@@ -121,9 +120,6 @@ data ModalWidget' model where
121120
ModalWidget' model
122121

123122
field ::
124-
forall model action t.
125-
( Typeable t
126-
) =>
127123
Full model action t Unique ->
128124
Opts model action ->
129125
[View action]
@@ -157,20 +153,12 @@ field full@Full {fullArgs = args, fullParser = parser, fullViewer = viewer} opts
157153
(optsLabel opts)
158154
( ( if typ == FieldTypeImage
159155
then do
160-
out <- maybeToList $ st ^? cloneTraversal optic . #fieldOutput
161156
src <-
162-
case typeRep @t `eqTypeRep` typeRep @DynamicField of
163-
Nothing ->
164-
maybeToList
165-
$ st
166-
^? cloneTraversal optic
167-
. #fieldInput
168-
. #uniqueValue
169-
Just HRefl ->
170-
case out of
171-
DynamicFieldRfc2397 (Just ref) _ -> [ref]
172-
DynamicFieldRfc2397 {} -> mempty
173-
_ -> [inspectDynamicField out]
157+
maybeToList
158+
$ st
159+
^? cloneTraversal optic
160+
. #fieldInput
161+
. #uniqueValue
174162
if null src
175163
then mempty
176164
else
@@ -349,8 +337,6 @@ passwordField args opts =
349337
)
350338

351339
fieldIcon ::
352-
( Typeable t
353-
) =>
354340
Full model action t Unique ->
355341
Opts model action ->
356342
OptsWidget model action ->
@@ -600,8 +586,7 @@ selectTypeWidget args@Args {argsAction = action} optic =
600586
-- TODO : support optional copying widgets
601587
--
602588
fieldViewer ::
603-
( Typeable t,
604-
Foldable1 f
589+
( Foldable1 f
605590
) =>
606591
Opts model action ->
607592
Args model action t f ->
@@ -657,9 +642,7 @@ header txt =
657642
]
658643

659644
genericFieldViewer ::
660-
forall model action t f.
661-
( Typeable t,
662-
Foldable1 f
645+
( Foldable1 f
663646
) =>
664647
Opts model action ->
665648
Args model action t f ->
@@ -676,20 +659,11 @@ genericFieldViewer opts0 args widget =
676659
<> ( optsLeftRightViewer
677660
opts0
678661
( if typ == FieldTypeImage
679-
then do
680-
out <- maybeToList $ st ^? cloneTraversal optic . #fieldOutput
681-
src <-
682-
case typeRep @t `eqTypeRep` typeRep @DynamicField of
683-
Nothing -> [input]
684-
Just HRefl ->
685-
case out of
686-
DynamicFieldRfc2397 (Just ref) _ -> [ref]
687-
DynamicFieldRfc2397 {} -> mempty
688-
_ -> [inspectDynamicField out]
689-
if null src
662+
then
663+
if null input
690664
then mempty
691665
else
692-
[ img_ [loading_ "lazy", src_ src]
666+
[ img_ [loading_ "lazy", src_ input]
693667
]
694668
else
695669
[ widget
@@ -815,45 +789,27 @@ expandDynamicField x =
815789
out = x ^. #fieldOutput
816790

817791
insertAction ::
818-
forall model action t.
819-
( Typeable t
820-
) =>
821792
Full model action t Unique ->
822793
((Maybe Unicode -> JSM ()) -> JSM ()) ->
823794
action
824795
insertAction Full {fullArgs = args, fullParser = parser} selector =
825-
action . ImpureUpdate $ do
826-
selector $ \case
827-
Nothing -> Jsm.popupText @Unicode "Failure!"
828-
Just inp -> do
829-
let updateInput =
830-
cloneTraversal optic
831-
. #fieldInput
832-
. #uniqueValue
833-
.~ inp
834-
case updateInput prev ^? cloneTraversal optic >>= parser of
835-
Nothing -> Jsm.popupText @Unicode "Failure!"
836-
Just out ->
837-
emitter . ImpureUpdate $ do
838-
Jsm.popupText @Unicode "Success!"
839-
let updateOutput = cloneTraversal optic . #fieldOutput .~ out
840-
case typeRep @t `eqTypeRep` typeRep @DynamicField of
841-
Nothing -> pure $ updateInput . updateOutput
842-
Just HRefl ->
843-
case out of
844-
DynamicFieldRfc2397 Just {} _ ->
845-
pure $ updateInput . updateOutput
846-
DynamicFieldRfc2397 Nothing val -> do
847-
ref <- Jsm.newBlobUrl inp
848-
pure
849-
$ updateInput
850-
. ( cloneTraversal optic
851-
. #fieldOutput
852-
.~ DynamicFieldRfc2397 (Just ref) val
853-
)
854-
_ ->
855-
pure $ updateInput . updateOutput
856-
pure id
796+
action . EffectUpdate . selector $ \case
797+
Nothing -> Jsm.popupText @Unicode "Failure!"
798+
Just inp -> do
799+
let updateInput =
800+
cloneTraversal optic
801+
. #fieldInput
802+
. #uniqueValue
803+
.~ inp
804+
case updateInput prev ^? cloneTraversal optic >>= parser of
805+
Nothing -> Jsm.popupText @Unicode "Failure!"
806+
Just out ->
807+
emitter
808+
. PureAndEffectUpdate
809+
( updateInput
810+
. (cloneTraversal optic . #fieldOutput .~ out)
811+
)
812+
$ Jsm.popupText @Unicode "Success!"
857813
where
858814
prev = args ^. #argsModel
859815
optic = args ^. #argsOptic

0 commit comments

Comments
 (0)