Skip to content

Commit be1d461

Browse files
committed
can use uuid with ghcjs
1 parent bd47744 commit be1d461

File tree

9 files changed

+52
-20
lines changed

9 files changed

+52
-20
lines changed

ghcjs/currency-converter/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ dist-newstyle
44
node_modules
55
dist
66
android
7+
capacitor-geckoview/capacitor/build

ghcjs/currency-converter/Main.hs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ data TopOrBottom
8282
deriving stock (Eq, Ord, Show, Read, Enum, Bounded, Data, Generic)
8383

8484
data ModelMoney = ModelMoney
85-
{ modelMoneyAmountInput :: Text,
85+
{ modelMoneyAmountUuid :: UUID,
86+
modelMoneyAmountInput :: Text,
8687
modelMoneyAmountOutput :: Money (Tags 'Signed |+| 'MoneyAmount),
8788
modelMoneyCurrencyInfo :: CurrencyInfo,
8889
modelMoneyCurrencyOpen :: Bool,
@@ -97,12 +98,14 @@ data ModelData = ModelData
9798
}
9899
deriving stock (Eq, Ord, Show, Read, Data, Generic)
99100

100-
mkModel :: (MonadThrow m, MonadUnliftIO m) => m Model
101-
mkModel = do
101+
newModel :: (MonadThrow m, MonadUnliftIO m) => m Model
102+
newModel = do
102103
ct <- getCurrentTime
103104
prod <- liftIO newBroadcastTChanIO
104105
cons <- liftIO . atomically $ dupTChan prod
105106
market <- newMarket
107+
topUuid <- newUuid
108+
bottomUuid <- newUuid
106109
let btc =
107110
CurrencyInfo
108111
{ currencyInfoCode = CurrencyCode "btc",
@@ -118,15 +121,17 @@ mkModel = do
118121
ModelData
119122
{ modelDataTopMoney =
120123
ModelMoney
121-
{ modelMoneyAmountInput = inspectMoneyAmount zero,
124+
{ modelMoneyAmountUuid = topUuid,
125+
modelMoneyAmountInput = inspectMoneyAmount zero,
122126
modelMoneyAmountOutput = zero,
123127
modelMoneyCurrencyInfo = btc,
124128
modelMoneyCurrencyOpen = False,
125129
modelMoneyCurrencySearch = mempty
126130
},
127131
modelDataBottomMoney =
128132
ModelMoney
129-
{ modelMoneyAmountInput = inspectMoneyAmount zero,
133+
{ modelMoneyAmountUuid = bottomUuid,
134+
modelMoneyAmountInput = inspectMoneyAmount zero,
130135
modelMoneyAmountOutput = zero,
131136
modelMoneyCurrencyInfo = usd,
132137
modelMoneyCurrencyOpen = False,
@@ -167,15 +172,17 @@ mkModel = do
167172
ModelData
168173
{ modelDataTopMoney =
169174
ModelMoney
170-
{ modelMoneyAmountInput = inspectMoneyAmount baseAmt,
175+
{ modelMoneyAmountUuid = topUuid,
176+
modelMoneyAmountInput = inspectMoneyAmount baseAmt,
171177
modelMoneyAmountOutput = unTag @'Base baseAmt,
172178
modelMoneyCurrencyInfo = baseCur,
173179
modelMoneyCurrencyOpen = False,
174180
modelMoneyCurrencySearch = mempty
175181
},
176182
modelDataBottomMoney =
177183
ModelMoney
178-
{ modelMoneyAmountInput = inspectMoneyAmount quoteAmt,
184+
{ modelMoneyAmountUuid = bottomUuid,
185+
modelMoneyAmountInput = inspectMoneyAmount quoteAmt,
179186
modelMoneyAmountOutput = unTag @'Quote quoteAmt,
180187
modelMoneyCurrencyInfo = quoteCur,
181188
modelMoneyCurrencyOpen = False,
@@ -231,7 +238,7 @@ extendedEvents =
231238

232239
main :: IO ()
233240
main = do
234-
st <- mkModel
241+
st <- newModel
235242
runApp
236243
$ startApp
237244
App
@@ -336,7 +343,7 @@ syncInputs st =
336343
forM_ enumerate $ \loc -> do
337344
JS.eval @Text
338345
$ "var el = document.getElementById('"
339-
<> inspect loc
346+
<> htmlUuid (st ^. #modelData . getMoneyOptic loc . #modelMoneyAmountUuid)
340347
<> "'); if (el && !(el.getElementsByTagName('input')[0] === document.activeElement)) el.value = '"
341348
<> (st ^. #modelData . getMoneyOptic loc . #modelMoneyAmountInput)
342349
<> "';"
@@ -533,12 +540,19 @@ amountWidget st loc =
533540
)
534541
& TextField.setAttributes
535542
[ class_ "fill",
536-
id_ $ inspect loc,
543+
id_
544+
. ms
545+
. htmlUuid @Text
546+
$ st
547+
^. #modelData
548+
. getMoneyOptic loc
549+
. #modelMoneyAmountUuid,
537550
onKeyDown onKeyDownAction,
538551
onBlur onBlurAction
539552
]
540553
]
541554
where
555+
uuid = st ^. #modelData . getMoneyOptic loc . #modelMoneyAmountUuid
542556
input = st ^. #modelData . getMoneyOptic loc . #modelMoneyAmountInput
543557
output = st ^. #modelData . getMoneyOptic loc . #modelMoneyAmountOutput
544558
valid =
@@ -561,7 +575,7 @@ amountWidget st loc =
561575
. void
562576
. JS.eval @Text
563577
$ "document.getElementById('"
564-
<> inspect loc
578+
<> htmlUuid uuid
565579
<> "').getElementsByTagName('input')[0].blur();"
566580
)
567581
( ChanItem 300 id
@@ -589,11 +603,11 @@ amountWidget st loc =
589603
onClearAction =
590604
PushUpdate
591605
( do
592-
focus $ inspect loc
606+
focus . ms $ htmlUuid @Text uuid
593607
void
594608
. JS.eval @Text
595609
$ "var el = document.getElementById('"
596-
<> inspect loc
610+
<> htmlUuid uuid
597611
<> "'); if (el) el.value = '';"
598612
)
599613
( ChanItem 300 $ \st' ->

ghcjs/currency-converter/android.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ with (import ./default.nix); let
5151
--android --assetPath static
5252
${pkgs.nodejs}/bin/npx trapeze run trapeze.yaml -y \
5353
--android-project android
54-
printf "include ':capacitor-android'\nproject(':capacitor-android').projectDir = new File('../../../pub/capacitor-geckoview/capacitor')" > ./android/capacitor.settings.gradle
54+
printf "include ':capacitor-android'\nproject(':capacitor-android').projectDir = new File('../capacitor-geckoview/capacitor')" > ./android/capacitor.settings.gradle
5555
)
5656
'';
5757
};

ghcjs/currency-converter/default.nix

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
let
2-
# functora = ../..;
3-
functora = fetchTarball {
4-
url = "https://github.com/functora/functora.github.io/archive/687980745c94639d3a8479363d4195b5d0c45033.tar.gz";
5-
sha256 = "0rzkhwwkal0rpif4sjmp61viq0afm3d9lmlkj8vyr4fv5zk7ydjn";
6-
};
2+
functora = ../..;
3+
# functora = fetchTarball {
4+
# url = "https://github.com/functora/functora.github.io/archive/687980745c94639d3a8479363d4195b5d0c45033.tar.gz";
5+
# sha256 = "0rzkhwwkal0rpif4sjmp61viq0afm3d9lmlkj8vyr4fv5zk7ydjn";
6+
# };
77
functora-miso = import "${functora}/ghcjs/miso/default.nix" {
88
overlays = import ./overlays.nix {inherit functora;};
99
};

ghcjs/currency-converter/overlays.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
ver = "0.1.1.1";
6262
sha256 = "EIIBNte4+s9s3lthoh1kj/qviuK+zlvBgNpKC0MmHcM=";
6363
} {};
64+
uuid = doJailbreak (self.callHackageDirect {
65+
pkg = "uuid";
66+
ver = "1.3.11";
67+
sha256 = "MGfh19sw6wjqknzHLgfDLet1m0pTISe7rsdl/OSwnFM=";
68+
} {});
6469
#
6570
# Local
6671
#

pub/functora/functora.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ common pkg-prelude
108108
, unbounded-delays
109109
, universum
110110
, unliftio
111+
, uuid
111112
, witch-mini
112113
, with-utf8
113114

pub/functora/src/functora-ghcjs.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ library
117117
, unbounded-delays
118118
, universum
119119
, unliftio
120+
, uuid
120121
, vector
121122
, witch-mini
122123
, with-utf8

pub/functora/src/prelude/Functora/Prelude.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ module Functora.Prelude
6969
altM,
7070
altM',
7171
takeWhileAcc,
72+
newUuid,
73+
htmlUuid,
7274
)
7375
where
7476

@@ -145,6 +147,9 @@ import qualified Data.Time.Clock as Clock
145147
import Data.Time.Clock.POSIX as X (posixSecondsToUTCTime)
146148
import Data.Tuple.Extra as X (uncurry3)
147149
import qualified Data.Typeable as Typeable
150+
import Data.UUID as X (UUID)
151+
import qualified Data.UUID as UUID
152+
import qualified Data.UUID.V4 as UUID
148153
import Functora.PreludeOrphan as X ()
149154
import GHC.Generics as X (Rep)
150155
import GHC.TypeLits as X (KnownSymbol, Symbol)
@@ -698,3 +703,9 @@ takeWhileAcc f prev (x : xs) =
698703
case f x prev of
699704
Nothing -> []
700705
Just next -> x : takeWhileAcc f next xs
706+
707+
newUuid :: (MonadIO m) => m UUID
708+
newUuid = liftIO UUID.nextRandom
709+
710+
htmlUuid :: forall a. (From Text a) => UUID -> a
711+
htmlUuid = from @Text @a . ("uuid-" <>) . UUID.toText

pub/functora/src/sql/Functora/SqlOrphan.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
module Functora.SqlOrphan () where
55

66
import qualified Data.Data as Data
7-
import Data.UUID (UUID)
87
import qualified Data.UUID as UUID
98
import Database.Esqueleto.Legacy hiding (from)
109
import Functora.Money

0 commit comments

Comments
 (0)