@@ -40,7 +40,7 @@ fav st =
40
40
)
41
41
( Field. defOpts
42
42
& # optsPlaceholder
43
- .~ (" Name - " <> fullFavName )
43
+ .~ (" Name - " <> makeFavName st )
44
44
),
45
45
Cell. smallCell
46
46
$ Button. raised
@@ -56,7 +56,7 @@ fav st =
56
56
Cell. smallCell
57
57
$ Button. raised
58
58
( Button. config
59
- & Button. setOnClick Noop
59
+ & Button. setOnClick deleteAction
60
60
& Button. setIcon (Just " delete_forever" )
61
61
& Button. setAttributes
62
62
[ Theme. secondaryBg,
@@ -78,28 +78,43 @@ fav st =
78
78
)
79
79
]
80
80
where
81
- fullFavName = makeFavName st
82
81
closeAction = pureUpdate 0 (& # modelFav .~ Closed )
83
82
saveAction = PushUpdate $ do
84
83
ct <- getCurrentTime
85
- uri <- URI. mkURI $ shareLink (st ^. # modelState . # stScreen) st
86
- let nextFav =
87
- Fav
88
- { favUri = uri,
89
- favCreatedAt = ct
90
- }
91
- pure
92
- . ChanItem 0
93
- $ ( Misc. textPopupPure
94
- $ " Saved "
95
- <> fullFavName
96
- <> " !"
97
- )
98
- . ( &
99
- # modelFavMap
100
- . at fullFavName
101
- %~ (Just . maybe nextFav (& # favUri .~ uri))
102
- )
84
+ pure . ChanItem 0 $ \ nextSt ->
85
+ let uri =
86
+ either impureThrow id
87
+ . URI. mkURI
88
+ $ shareLink (nextSt ^. # modelState . # stScreen) nextSt
89
+ nextFav = do
90
+ Fav
91
+ { favUri = uri,
92
+ favCreatedAt = ct
93
+ }
94
+ nextFavName =
95
+ makeFavName nextSt
96
+ in nextSt
97
+ & ( Misc. textPopupPure
98
+ $ " Saved "
99
+ <> nextFavName
100
+ <> " !"
101
+ )
102
+ & # modelFavMap
103
+ . at nextFavName
104
+ %~ ( Just
105
+ . maybe nextFav (& # favUri .~ uri)
106
+ )
107
+ deleteAction = pureUpdate 0 $ \ nextSt ->
108
+ let nextFavName = makeFavName nextSt
109
+ in nextSt
110
+ & ( Misc. textPopupPure
111
+ $ " Removed "
112
+ <> nextFavName
113
+ <> " !"
114
+ )
115
+ & # modelFavMap
116
+ . at nextFavName
117
+ .~ Nothing
103
118
104
119
makeFavName :: Model -> Text
105
120
makeFavName st =
@@ -144,12 +159,15 @@ favItem st label Fav {favUri = uri} =
144
159
Cell. bigCell
145
160
$ Button. raised
146
161
( Button. config
147
- & Button. setOnClick opened
162
+ & Button. setOnClick openAction
148
163
& Button. setAttributes [class_ " fill" ]
149
164
)
150
165
label
151
166
where
152
- opened = PushUpdate $ do
167
+ openAction = PushUpdate $ do
168
+ --
169
+ -- TODO : Implement here pure, less costly equivalent of newModel.
170
+ --
153
171
next <- newModel (st ^. # modelWebOpts) (Just st) uri
154
172
pure
155
173
. ChanItem 0
0 commit comments