Skip to content

Commit 89f8d3f

Browse files
committed
wip
1 parent cac9eb9 commit 89f8d3f

File tree

3 files changed

+101
-104
lines changed

3 files changed

+101
-104
lines changed

ghcjs/lightning-verifier/src/App/Widgets/Main.hs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@ screenWidget st@Model {modelState = St {stCpt = Just {}}} =
7575
)
7676
<> Qr.qr out
7777
<> [ Grid.bigCell
78-
$ genericFieldViewer
78+
$ Field.dynamicFieldViewer
7979
(PushUpdate . Instant)
80-
(newFieldId FieldTypeText id out)
81-
text
80+
(newDynamicFieldId $ DynamicFieldText out)
8281
]
8382
<> [ Grid.bigCell
8483
[ Button.raised
@@ -104,10 +103,9 @@ screenWidget st@Model {modelState = St {stScreen = QrCode sc}} =
104103
)
105104
<> Qr.qr out
106105
<> [ Grid.bigCell
107-
$ genericFieldViewer
106+
$ Field.dynamicFieldViewer
108107
(PushUpdate . Instant)
109-
(newFieldId FieldTypeText id out)
110-
text
108+
(newDynamicFieldId $ DynamicFieldText out)
111109
]
112110
<> [ Grid.bigCell
113111
[ Button.raised

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

Lines changed: 12 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ module Functora.Miso.Types
1313
newTextField,
1414
newPasswordField,
1515
newDynamicField,
16+
newDynamicFieldId,
1617
newDynamicTitleField,
17-
genericFieldViewer,
1818
DynamicField (..),
1919
parseDynamicField,
2020
inspectDynamicField,
@@ -55,14 +55,9 @@ import Data.Foldable (Foldable (..))
5555
import Data.Functor.Barbie
5656
import qualified Data.Generics as Syb
5757
import Functora.Cfg
58-
import qualified Functora.Miso.Css as Css
59-
import qualified Functora.Miso.Jsm.Generic as Jsm
6058
import Functora.Miso.Prelude
6159
import Functora.Money hiding (Currency, Money, Text)
6260
import qualified Functora.Prelude as Prelude
63-
import qualified Material.IconButton as IconButton
64-
import qualified Material.Theme as Theme
65-
import qualified Material.Typography as Typography
6661
import qualified Text.URI as URI
6762

6863
type Typ a =
@@ -186,72 +181,23 @@ newDynamicField output =
186181
output
187182
inspectDynamicField
188183

184+
newDynamicFieldId :: DynamicField -> Field DynamicField Identity
185+
newDynamicFieldId output =
186+
newFieldId
187+
( case output of
188+
DynamicFieldNumber {} -> FieldTypeNumber
189+
DynamicFieldText {} -> FieldTypeText
190+
)
191+
inspectDynamicField
192+
output
193+
189194
newDynamicTitleField ::
190195
(MonadIO m) => MisoString -> m (Field DynamicField Unique)
191196
newDynamicTitleField =
192197
fmap (& #fieldType .~ FieldTypeTitle)
193198
. newDynamicField
194199
. DynamicFieldText
195200

196-
genericFieldViewer ::
197-
( Foldable1 f
198-
) =>
199-
((model -> JSM model) -> action) ->
200-
Field typ f ->
201-
(MisoString -> View action) ->
202-
[View action]
203-
genericFieldViewer action value widget =
204-
if input == mempty
205-
then mempty
206-
else
207-
[ span_
208-
[ Typography.typography,
209-
Css.fullWidth,
210-
class_ "mdc-text-field",
211-
class_ "mdc-text-field--filled",
212-
style_
213-
[ ("align-items", "center"),
214-
("align-content", "center"),
215-
("word-break", "normal"),
216-
("overflow-wrap", "anywhere"),
217-
("min-height", "56px"),
218-
("height", "auto"),
219-
("padding-top", "8px"),
220-
("padding-bottom", "8px"),
221-
("border-radius", "4px"),
222-
("line-height", "150%")
223-
]
224-
]
225-
[ div_ mempty
226-
$ [ widget $ toMisoString input
227-
]
228-
<> ( if not allowCopy
229-
then mempty
230-
else
231-
[ IconButton.iconButton
232-
( IconButton.config
233-
& IconButton.setOnClick
234-
( action $ Jsm.shareText input
235-
)
236-
& IconButton.setAttributes
237-
[ Theme.primary,
238-
style_
239-
[ ("height", "auto"),
240-
("padding-top", "inherit"),
241-
("padding-bottom", "inherit"),
242-
("vertical-align", "middle")
243-
]
244-
]
245-
)
246-
"content_copy"
247-
]
248-
)
249-
]
250-
]
251-
where
252-
input = fold1 $ value ^. #fieldInput
253-
allowCopy = value ^. #fieldAllowCopy
254-
255201
data DynamicField
256202
= DynamicFieldText MisoString
257203
| DynamicFieldNumber Rational
@@ -339,14 +285,7 @@ newFieldPairId :: MisoString -> DynamicField -> FieldPair DynamicField Identity
339285
newFieldPairId key val =
340286
FieldPair
341287
(newFieldId FieldTypeText id key)
342-
( newFieldId
343-
( case val of
344-
DynamicFieldNumber {} -> FieldTypeNumber
345-
DynamicFieldText {} -> FieldTypeText
346-
)
347-
inspectDynamicField
348-
val
349-
)
288+
(newDynamicFieldId val)
350289

351290
data Currency f = Currency
352291
{ currencyInput :: Field MisoString f,

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

Lines changed: 85 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import qualified Functora.Miso.Widgets.Grid as Grid
2424
import qualified Functora.Miso.Widgets.Qr as Qr
2525
import qualified Language.Javascript.JSaddle as JS
2626
import qualified Material.Button as Button
27+
import qualified Material.IconButton as IconButton
2728
import qualified Material.LayoutGrid as LayoutGrid
2829
import qualified Material.Select as Select
2930
import qualified Material.Select.Item as SelectItem
@@ -710,6 +711,31 @@ constTextField txt opts action =
710711
)
711712
]
712713

714+
cell :: Opts model action -> [View action] -> View action
715+
cell Opts {optsFullWidth = full} =
716+
LayoutGrid.cell
717+
$ if full
718+
then
719+
[ LayoutGrid.span12Desktop,
720+
LayoutGrid.span8Tablet,
721+
LayoutGrid.span4Phone,
722+
LayoutGrid.alignMiddle,
723+
style_
724+
[ ("display", "flex"),
725+
("align-items", "center")
726+
]
727+
]
728+
else
729+
[ LayoutGrid.span6Desktop,
730+
LayoutGrid.span4Tablet,
731+
LayoutGrid.span4Phone,
732+
LayoutGrid.alignMiddle,
733+
style_
734+
[ ("display", "flex"),
735+
("align-items", "center")
736+
]
737+
]
738+
713739
--
714740
-- TODO : support optional copying widgets
715741
--
@@ -728,7 +754,7 @@ dynamicFieldViewer action value =
728754
FieldTypeTitle -> header out
729755
FieldTypeHtml -> genericFieldViewer action value rawHtml
730756
FieldTypePassword -> genericFieldViewer action value $ const "*****"
731-
FieldTypeQrCode -> Qr.qr out
757+
FieldTypeQrCode -> Qr.qr out <> genericFieldViewer action value text
732758
where
733759
--
734760
-- TODO : use input instead!!!
@@ -749,27 +775,61 @@ header txt =
749775
]
750776
]
751777

752-
cell :: Opts model action -> [View action] -> View action
753-
cell Opts {optsFullWidth = full} =
754-
LayoutGrid.cell
755-
$ if full
756-
then
757-
[ LayoutGrid.span12Desktop,
758-
LayoutGrid.span8Tablet,
759-
LayoutGrid.span4Phone,
760-
LayoutGrid.alignMiddle,
761-
style_
762-
[ ("display", "flex"),
763-
("align-items", "center")
764-
]
765-
]
766-
else
767-
[ LayoutGrid.span6Desktop,
768-
LayoutGrid.span4Tablet,
769-
LayoutGrid.span4Phone,
770-
LayoutGrid.alignMiddle,
771-
style_
772-
[ ("display", "flex"),
773-
("align-items", "center")
774-
]
775-
]
778+
genericFieldViewer ::
779+
( Foldable1 f
780+
) =>
781+
((model -> JSM model) -> action) ->
782+
Field typ f ->
783+
(MisoString -> View action) ->
784+
[View action]
785+
genericFieldViewer action value widget =
786+
if input == mempty
787+
then mempty
788+
else
789+
[ span_
790+
[ Typography.typography,
791+
Css.fullWidth,
792+
class_ "mdc-text-field",
793+
class_ "mdc-text-field--filled",
794+
style_
795+
[ ("align-items", "center"),
796+
("align-content", "center"),
797+
("word-break", "normal"),
798+
("overflow-wrap", "anywhere"),
799+
("min-height", "56px"),
800+
("height", "auto"),
801+
("padding-top", "8px"),
802+
("padding-bottom", "8px"),
803+
("border-radius", "4px"),
804+
("line-height", "150%")
805+
]
806+
]
807+
[ div_ mempty
808+
$ [ widget $ toMisoString input
809+
]
810+
<> ( if not allowCopy
811+
then mempty
812+
else
813+
[ IconButton.iconButton
814+
( IconButton.config
815+
& IconButton.setOnClick
816+
( action $ Jsm.shareText input
817+
)
818+
& IconButton.setAttributes
819+
[ Theme.primary,
820+
style_
821+
[ ("height", "auto"),
822+
("padding-top", "inherit"),
823+
("padding-bottom", "inherit"),
824+
("vertical-align", "middle")
825+
]
826+
]
827+
)
828+
"content_copy"
829+
]
830+
)
831+
]
832+
]
833+
where
834+
input = fold1 $ value ^. #fieldInput
835+
allowCopy = value ^. #fieldAllowCopy

0 commit comments

Comments
 (0)