@@ -27,7 +27,6 @@ import qualified Functora.Miso.Widgets.Qr as Qr
27
27
import qualified Functora.Miso.Widgets.Select as Select
28
28
import qualified Language.Javascript.JSaddle as JS
29
29
import qualified Miso.String as MS
30
- import Type.Reflection
31
30
32
31
data Args model action t f = Args
33
32
{ argsModel :: model ,
@@ -121,9 +120,6 @@ data ModalWidget' model where
121
120
ModalWidget' model
122
121
123
122
field ::
124
- forall model action t .
125
- ( Typeable t
126
- ) =>
127
123
Full model action t Unique ->
128
124
Opts model action ->
129
125
[View action ]
@@ -157,20 +153,12 @@ field full@Full {fullArgs = args, fullParser = parser, fullViewer = viewer} opts
157
153
(optsLabel opts)
158
154
( ( if typ == FieldTypeImage
159
155
then do
160
- out <- maybeToList $ st ^? cloneTraversal optic . # fieldOutput
161
156
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
174
162
if null src
175
163
then mempty
176
164
else
@@ -349,8 +337,6 @@ passwordField args opts =
349
337
)
350
338
351
339
fieldIcon ::
352
- ( Typeable t
353
- ) =>
354
340
Full model action t Unique ->
355
341
Opts model action ->
356
342
OptsWidget model action ->
@@ -600,8 +586,7 @@ selectTypeWidget args@Args {argsAction = action} optic =
600
586
-- TODO : support optional copying widgets
601
587
--
602
588
fieldViewer ::
603
- ( Typeable t ,
604
- Foldable1 f
589
+ ( Foldable1 f
605
590
) =>
606
591
Opts model action ->
607
592
Args model action t f ->
@@ -657,9 +642,7 @@ header txt =
657
642
]
658
643
659
644
genericFieldViewer ::
660
- forall model action t f .
661
- ( Typeable t ,
662
- Foldable1 f
645
+ ( Foldable1 f
663
646
) =>
664
647
Opts model action ->
665
648
Args model action t f ->
@@ -676,20 +659,11 @@ genericFieldViewer opts0 args widget =
676
659
<> ( optsLeftRightViewer
677
660
opts0
678
661
( 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
690
664
then mempty
691
665
else
692
- [ img_ [loading_ " lazy" , src_ src ]
666
+ [ img_ [loading_ " lazy" , src_ input ]
693
667
]
694
668
else
695
669
[ widget
@@ -815,45 +789,27 @@ expandDynamicField x =
815
789
out = x ^. # fieldOutput
816
790
817
791
insertAction ::
818
- forall model action t .
819
- ( Typeable t
820
- ) =>
821
792
Full model action t Unique ->
822
793
((Maybe Unicode -> JSM () ) -> JSM () ) ->
823
794
action
824
795
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!"
857
813
where
858
814
prev = args ^. # argsModel
859
815
optic = args ^. # argsOptic
0 commit comments