Skip to content

Commit 0f6ecee

Browse files
committed
uri sync wip
1 parent fe8934b commit 0f6ecee

File tree

8 files changed

+140
-120
lines changed

8 files changed

+140
-120
lines changed

ghcjs/currency-converter/app.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ common pkg
121121
, miso
122122
, miso-components
123123
, modern-uri
124+
, network-uri
124125
, qrcode-core
125126
, random
126127
, syb

ghcjs/currency-converter/package-lock.json

Lines changed: 113 additions & 113 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ module App.Types
1313
pureUpdate,
1414
unShareUri,
1515
stUri,
16-
baseUri,
1716
setScreenPure,
1817
setScreenAction,
1918
shareLink,
@@ -249,7 +248,7 @@ stQuery st = do
249248

250249
stUri :: (MonadThrow m) => Model -> m URI
251250
stUri st = do
252-
uri <- mkURI $ from @MisoString @Prelude.Text baseUri
251+
uri <- mkURI $ fromMisoString baseUri
253252
qxs <- stQuery . uniqueToIdentity $ st ^. #modelState
254253
pure
255254
$ uri

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ qr st txt opts
6060
extraCell
6161
$ Button.raised
6262
( Button.config
63-
& Button.setIcon (Just "content_copy")
63+
& Button.setIcon (Just "share")
6464
& Button.setAttributes [class_ "fill"]
6565
& Button.setOnClick (Misc.copyIntoClipboardAction st txt)
6666
)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,17 @@ newModel webOpts mSt uri = do
122122
newDonateDoc :: IO (StDoc Unique)
123123
newDonateDoc = do
124124
doc <- newStDoc
125+
topMoney <- newMoney 5 usd
126+
bottomMoney <- newMoney 0 btc
125127
title <- newFieldPair mempty $ DynamicFieldText "Hello, User!"
126128
message <- newFieldPair mempty $ DynamicFieldText exampleDonationText
127129
btcMtd <- newFieldPair "BTC - Bitcoin" $ DynamicFieldText exampleBtcAddress
128130
xmrMtd <- newFieldPair "XMR - Monero" $ DynamicFieldText exampleXmrAddress
129131
pure
130132
doc
131-
{ stDocFieldPairs =
133+
{ stDocTopMoney = topMoney,
134+
stDocBottomMoney = bottomMoney,
135+
stDocFieldPairs =
132136
[ title
133137
& #fieldPairValue
134138
. #fieldType

ghcjs/currency-converter/src/Main.hs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import qualified Functora.Web as Web
3131
import Language.Javascript.JSaddle ((!), (!!))
3232
import qualified Language.Javascript.JSaddle as JS
3333
import qualified Miso
34+
import qualified Network.URI as URI (parseURI)
3435
import qualified Text.URI as URI
3536

3637
#ifdef wasi_HOST_OS
@@ -199,10 +200,12 @@ updateModel (ChanUpdate prevSt) _ = do
199200
consoleLog e
200201
pure $ prevSt & #modelLoading .~ False
201202
)
202-
$ foldlM (\acc updater -> evalModel $ updater acc) prevSt actions
203+
. evalModel
204+
$ foldl (&) prevSt actions
203205
uri <- URI.mkURI $ shareLink nextSt
204206
Storage.insertStorage ("favorite-" <> vsn) (nextSt ^. #modelFavMap)
205207
Storage.insertStorage ("current-" <> vsn) uri
208+
syncUri uri
206209
if nextSt ^. #modelLoading
207210
then do
208211
void
@@ -395,6 +398,19 @@ evalModel raw = do
395398
& #modelOnlineAt
396399
.~ ct
397400

401+
syncUri :: URI -> JSM ()
402+
syncUri uri = do
403+
textUri <- fmap Prelude.inspect getCurrentURI
404+
prevUri <- URI.mkURI textUri
405+
let nextUri = prevUri {URI.uriQuery = URI.uriQuery uri}
406+
when (nextUri /= prevUri)
407+
$ pushURI
408+
=<< ( maybe (throwString $ "Bad URI " <> textUri) pure
409+
. URI.parseURI
410+
. from @Prelude.Text @Prelude.String
411+
$ URI.render nextUri
412+
)
413+
398414
getBaseConverterMoneyLens :: TopOrBottom -> ALens' Model (Money Unique)
399415
getBaseConverterMoneyLens = \case
400416
Top -> #modelState . #stDoc . #stDocTopMoney

ghcjs/currency-converter/static/cap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ async function insertStorage(key, value) {
1818

1919
async function openBrowserPage(url) {
2020
try {
21-
return await Browser.open({ url: url });
21+
return await Browser.open({ url: url, windowName: "_blank" });
2222
} catch (e) {
2323
return window.open(url, "_blank").focus();
2424
}

ghcjs/currency-converter/static/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ async function insertStorage(key, value) {
597597
}
598598
async function openBrowserPage(url) {
599599
try {
600-
return await Browser.open({ url });
600+
return await Browser.open({ url, windowName: "_blank" });
601601
} catch (e) {
602602
return window.open(url, "_blank").focus();
603603
}

0 commit comments

Comments
 (0)