Skip to content

Commit cac9eb9

Browse files
committed
refactoring wip
1 parent d8ffa06 commit cac9eb9

File tree

11 files changed

+585
-606
lines changed

11 files changed

+585
-606
lines changed

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,30 @@ import qualified System.Random as Random
1818
decrypt :: Model -> [View Action]
1919
decrypt st =
2020
[ Grid.bigCell
21-
. div_ mempty
2221
$ Field.dynamicFieldViewer
2322
(PushUpdate . Instant)
2423
(st ^. #modelState . #stPre),
2524
Grid.mediumCell
26-
$ Field.passwordField
27-
Field.Args
28-
{ Field.argsModel = st,
29-
Field.argsOptic = #modelState . #stIkm,
30-
Field.argsAction = PushUpdate . Instant
31-
}
32-
( Field.defOpts @Model @Action
33-
& #optsOnKeyDownAction
34-
.~ onKeyDownAction
35-
),
25+
[ Field.passwordField
26+
Field.Args
27+
{ Field.argsModel = st,
28+
Field.argsOptic = #modelState . #stIkm,
29+
Field.argsAction = PushUpdate . Instant
30+
}
31+
( Field.defOpts @Model @Action
32+
& #optsOnKeyDownAction
33+
.~ onKeyDownAction
34+
)
35+
],
3636
Grid.mediumCell
37-
$ Button.raised
38-
( Button.config
39-
& Button.setOnClick (PushUpdate $ Instant decryptDoc)
40-
& Button.setIcon (Just "login")
41-
& Button.setAttributes [Css.fullWidth]
42-
)
43-
"Open"
37+
[ Button.raised
38+
( Button.config
39+
& Button.setOnClick (PushUpdate $ Instant decryptDoc)
40+
& Button.setIcon (Just "login")
41+
& Button.setAttributes [Css.fullWidth]
42+
)
43+
"Open"
44+
]
4445
]
4546

4647
decryptDoc :: Model -> JSM Model

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

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,40 @@ fav st =
3232
mempty
3333
$ favItems st
3434
<> [ Grid.bigCell
35-
$ Field.textField
36-
Field.Args
37-
{ Field.argsModel = st,
38-
Field.argsOptic = #modelFavName,
39-
Field.argsAction = PushUpdate . Instant
40-
}
41-
Field.defOpts
42-
{ Field.optsPlaceholder = "Name",
43-
Field.optsFilledOrOutlined = Outlined,
44-
Field.optsOnKeyDownAction = onKeyDownAction,
45-
Field.optsTrailingWidget =
46-
Just
47-
. Field.ActionWidget
48-
"favorite"
49-
mempty
50-
. PushUpdate
51-
$ Instant saveAction,
52-
Field.optsLeadingWidget =
53-
Just
54-
$ Field.ActionWidget
55-
"delete_forever"
56-
mempty
57-
deleteAction
58-
},
35+
[ Field.textField
36+
Field.Args
37+
{ Field.argsModel = st,
38+
Field.argsOptic = #modelFavName,
39+
Field.argsAction = PushUpdate . Instant
40+
}
41+
Field.defOpts
42+
{ Field.optsPlaceholder = "Name",
43+
Field.optsFilledOrOutlined = Outlined,
44+
Field.optsOnKeyDownAction = onKeyDownAction,
45+
Field.optsTrailingWidget =
46+
Just
47+
. Field.ActionWidget
48+
"favorite"
49+
mempty
50+
. PushUpdate
51+
$ Instant saveAction,
52+
Field.optsLeadingWidget =
53+
Just
54+
$ Field.ActionWidget
55+
"delete_forever"
56+
mempty
57+
deleteAction
58+
}
59+
],
5960
Grid.bigCell
60-
$ Button.raised
61-
( Button.config
62-
& Button.setOnClick closeAction
63-
& Button.setIcon (Just "arrow_back")
64-
& Button.setAttributes [Css.fullWidth]
65-
)
66-
"Back"
61+
[ Button.raised
62+
( Button.config
63+
& Button.setOnClick closeAction
64+
& Button.setIcon (Just "arrow_back")
65+
& Button.setAttributes [Css.fullWidth]
66+
)
67+
"Back"
68+
]
6769
]
6870
]
6971
mempty
@@ -133,12 +135,13 @@ favItems st =
133135
favItem :: Model -> MisoString -> Fav -> View Action
134136
favItem st label Fav {favUri = uri} =
135137
Grid.bigCell
136-
$ Button.raised
137-
( Button.config
138-
& Button.setOnClick openAction
139-
& Button.setAttributes [Css.fullWidth]
140-
)
141-
label
138+
[ Button.raised
139+
( Button.config
140+
& Button.setOnClick openAction
141+
& Button.setAttributes [Css.fullWidth]
142+
)
143+
label
144+
]
142145
where
143146
openAction = PushUpdate . Instant $ \nextSt -> do
144147
--

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

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Functora.Miso.Prelude
1111
import qualified Functora.Miso.Widgets.BrowserLink as BrowserLink
1212
import qualified Functora.Miso.Widgets.Field as Field
1313
import qualified Functora.Miso.Widgets.FieldPairs as FieldPairs
14+
import qualified Functora.Miso.Widgets.Grid as Grid
1415
import qualified Functora.Miso.Widgets.Header as Header
1516
import qualified Functora.Miso.Widgets.Qr as Qr
1617
import qualified Material.Button as Button
@@ -58,64 +59,66 @@ mainWidget st =
5859
screenWidget :: Model -> [View Action]
5960
screenWidget st@Model {modelState = St {stCpt = Just {}}} =
6061
case st ^. #modelState . #stScreen of
61-
QrCode sc ->
62+
QrCode sc -> do
63+
let out =
64+
toMisoString
65+
. either impureThrow URI.render
66+
. stUri
67+
$ st
68+
& #modelState
69+
. #stScreen
70+
%~ unQrCode
6271
Header.headerWrapper
6372
( Field.dynamicFieldViewer
6473
(PushUpdate . Instant)
6574
(st ^. #modelState . #stPre)
6675
)
67-
<> Qr.qr
68-
Qr.Args
69-
{ Qr.argsValue =
70-
toMisoString
71-
. either impureThrow URI.render
72-
. stUri
73-
$ st
74-
& #modelState
75-
. #stScreen
76-
%~ unQrCode,
77-
Qr.argsAction =
78-
PushUpdate
79-
. Instant
80-
}
81-
( Qr.defOpts @Action
82-
& #optsExtraWidgets
83-
.~ [ Button.raised
84-
( Button.config
85-
& Button.setIcon (Just "login")
86-
& Button.setAttributes [Css.fullWidth]
87-
& Button.setOnClick (setScreenAction $ unQrCode sc)
88-
)
89-
"Open"
90-
]
91-
)
76+
<> Qr.qr out
77+
<> [ Grid.bigCell
78+
$ genericFieldViewer
79+
(PushUpdate . Instant)
80+
(newFieldId FieldTypeText id out)
81+
text
82+
]
83+
<> [ Grid.bigCell
84+
[ Button.raised
85+
( Button.config
86+
& Button.setIcon (Just "login")
87+
& Button.setAttributes [Css.fullWidth]
88+
& Button.setOnClick (setScreenAction $ unQrCode sc)
89+
)
90+
"Open"
91+
]
92+
]
9293
_ ->
9394
Decrypt.decrypt st
9495
screenWidget st@Model {modelState = St {stScreen = QrCode sc}} =
9596
case stUri $ st & #modelState . #stScreen %~ unQrCode of
9697
Left e -> impureThrow e
97-
Right uri ->
98+
Right uri -> do
99+
let out = toMisoString $ URI.render uri
98100
Header.headerWrapper
99101
( Field.dynamicFieldViewer
100102
(PushUpdate . Instant)
101103
(st ^. #modelState . #stPre)
102104
)
103-
<> Qr.qr
104-
Qr.Args
105-
{ Qr.argsValue = toMisoString $ URI.render uri,
106-
Qr.argsAction = PushUpdate . Instant
107-
}
108-
( Qr.defOpts @Action
109-
& #optsExtraWidgets
110-
.~ [ Button.raised
111-
( Button.config
112-
& Button.setIcon (Just "login")
113-
& Button.setAttributes [Css.fullWidth]
114-
& Button.setOnClick (setScreenAction $ unQrCode sc)
115-
)
116-
"Open"
117-
]
118-
)
105+
<> Qr.qr out
106+
<> [ Grid.bigCell
107+
$ genericFieldViewer
108+
(PushUpdate . Instant)
109+
(newFieldId FieldTypeText id out)
110+
text
111+
]
112+
<> [ Grid.bigCell
113+
[ Button.raised
114+
( Button.config
115+
& Button.setIcon (Just "login")
116+
& Button.setAttributes [Css.fullWidth]
117+
& Button.setOnClick (setScreenAction $ unQrCode sc)
118+
)
119+
"Open"
120+
]
121+
]
119122
screenWidget st@Model {modelState = St {stScreen = Converter}} =
120123
FieldPairs.fieldPairsViewer
121124
FieldPairs.Args

0 commit comments

Comments
 (0)