Skip to content

Commit 146a872

Browse files
committed
wip
1 parent 03df5e6 commit 146a872

File tree

3 files changed

+44
-25
lines changed

3 files changed

+44
-25
lines changed

ghcjs/currency-converter/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
let
22
# functora = ../..;
33
functora = fetchTarball {
4-
url = "https://github.com/functora/functora.github.io/archive/2b478d8e18769b245a2bc488d7136718e81c0ac1.tar.gz";
5-
sha256 = "0xxc2g2hiylk6hhbq6a0qk8a9cq7r0y5l0szm1rwcqlywdb8kg0l";
4+
url = "https://github.com/functora/functora.github.io/archive/03df5e6d39d0fdc31a53cc350e1125118b4a12ca.tar.gz";
5+
sha256 = "0pad1981bpnl1szvlhgl00ai9ikz9nsl4yv6mxxv0q46j10bdchz";
66
};
77
legacy = fetchTarball {
88
url = "https://github.com/functora/functora.github.io/archive/7a06c850a579058f495ca2d7e5e2f8682ea0998f.tar.gz";

ghcjs/currency-converter/src/App/Types.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ data Fav = Fav
386386
favCreatedAt :: UTCTime
387387
}
388388
deriving stock (Eq, Ord, Show, Data, Generic)
389+
deriving (ToJSON, FromJSON) via GenericType Fav
389390

390391
newRatioField :: (MonadIO m) => Rational -> m (Field Rational Unique)
391392
newRatioField output =

ghcjs/currency-converter/src/App/Widgets/Fav.hs

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fav st =
4040
)
4141
( Field.defOpts
4242
& #optsPlaceholder
43-
.~ ("Name - " <> fullFavName)
43+
.~ ("Name - " <> makeFavName st)
4444
),
4545
Cell.smallCell
4646
$ Button.raised
@@ -56,7 +56,7 @@ fav st =
5656
Cell.smallCell
5757
$ Button.raised
5858
( Button.config
59-
& Button.setOnClick Noop
59+
& Button.setOnClick deleteAction
6060
& Button.setIcon (Just "delete_forever")
6161
& Button.setAttributes
6262
[ Theme.secondaryBg,
@@ -78,28 +78,43 @@ fav st =
7878
)
7979
]
8080
where
81-
fullFavName = makeFavName st
8281
closeAction = pureUpdate 0 (& #modelFav .~ Closed)
8382
saveAction = PushUpdate $ do
8483
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
103118

104119
makeFavName :: Model -> Text
105120
makeFavName st =
@@ -144,12 +159,15 @@ favItem st label Fav {favUri = uri} =
144159
Cell.bigCell
145160
$ Button.raised
146161
( Button.config
147-
& Button.setOnClick opened
162+
& Button.setOnClick openAction
148163
& Button.setAttributes [class_ "fill"]
149164
)
150165
label
151166
where
152-
opened = PushUpdate $ do
167+
openAction = PushUpdate $ do
168+
--
169+
-- TODO : Implement here pure, less costly equivalent of newModel.
170+
--
153171
next <- newModel (st ^. #modelWebOpts) (Just st) uri
154172
pure
155173
. ChanItem 0

0 commit comments

Comments
 (0)