@@ -27,7 +27,6 @@ import qualified Functora.Miso.Widgets.Qr as Qr
2727import qualified Functora.Miso.Widgets.Select as Select
2828import qualified Language.Javascript.JSaddle as JS
2929import qualified Miso.String as MS
30- import Type.Reflection
3130
3231data Args model action t f = Args
3332 { argsModel :: model ,
@@ -121,9 +120,6 @@ data ModalWidget' model where
121120 ModalWidget' model
122121
123122field ::
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
351339fieldIcon ::
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--
602588fieldViewer ::
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
659644genericFieldViewer ::
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
817791insertAction ::
818- forall model action t .
819- ( Typeable t
820- ) =>
821792 Full model action t Unique ->
822793 ((Maybe Unicode -> JSM () ) -> JSM () ) ->
823794 action
824795insertAction 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