@@ -16,18 +16,18 @@ import qualified Language.Javascript.JSaddle.Wasm as JSaddle.Wasm
16
16
#endif
17
17
18
18
import qualified App.Misc as Misc
19
- import App.Prelude
20
19
import App.Types
21
20
import App.Widgets.Main
22
21
import App.Widgets.Templates
23
22
import qualified Data.Generics as Syb
24
23
import qualified Data.Map as Map
24
+ import Functora.Miso.Prelude
25
+ import qualified Functora.Miso.Storage as Storage
25
26
import Functora.Money hiding (Money )
26
27
import Functora.Rates
27
28
import qualified Functora.Web as Web
28
29
import Language.Javascript.JSaddle ((!) , (!!) )
29
30
import qualified Language.Javascript.JSaddle as JS
30
- import Miso hiding (view )
31
31
import qualified Miso
32
32
import qualified Text.URI as URI
33
33
40
40
withUtf8
41
41
. runApp
42
42
. forever
43
- . handleAny (\ e -> log e >> sleepSeconds 5 )
43
+ . handleAny (\ e -> consoleLog e >> sleepSeconds 5 )
44
44
$ do
45
45
uri <- URI. mkURI . inspect =<< getCurrentURI
46
46
ext <- unShareUri uri
@@ -127,7 +127,7 @@ updateModel (InitUpdate ext) prevSt = do
127
127
}
128
128
if isJust ext
129
129
then Misc. pushActionQueue nextSt $ ChanItem 0 (& # modelLoading .~ False )
130
- else selectCurrentUri $ \ case
130
+ else Storage. selectStorage ( " current- " <> vsn) $ \ case
131
131
Nothing ->
132
132
Misc. pushActionQueue nextSt $ ChanItem 0 (& # modelLoading .~ False )
133
133
Just uri -> do
@@ -174,11 +174,12 @@ updateModel (ChanUpdate prevSt) _ = do
174
174
nextSt <-
175
175
handleAny
176
176
( \ e -> do
177
- log e
177
+ consoleLog e
178
178
pure $ prevSt & # modelLoading .~ False
179
179
)
180
180
$ foldlM (\ acc updater -> evalModel $ updater acc) prevSt actions
181
- insertCurrentUri nextSt
181
+ uri <- URI. mkURI $ shareLink (nextSt ^. # modelState . # stScreen) nextSt
182
+ Storage. insertStorage (" current-" <> vsn) uri
182
183
if nextSt ^. # modelLoading
183
184
then do
184
185
void
@@ -241,22 +242,23 @@ extendedEvents =
241
242
syncInputs :: Model -> JSM ()
242
243
syncInputs st = do
243
244
void
244
- . JS. eval @ Text
245
+ . JS. eval @ MisoString
245
246
$ " Array.from(document.getElementsByTagName('mdc-text-field')).forEach( function (x) { if ( (x.getElementsByTagName('input')[0] && x.textField_.input_.tagName != 'INPUT') || (x.getElementsByTagName('textarea')[0] && x.textField_.input_.tagName != 'TEXTAREA')) { x.textField_.destroy(); x.textField_.initialize(); } });"
246
247
void
247
248
. Syb. everywhereM (Syb. mkM fun)
248
249
$ modelState st
249
250
where
250
- fun :: Unique Text -> JSM (Unique Text )
251
+ fun :: Unique MisoString -> JSM (Unique MisoString )
251
252
fun txt = do
252
- el <- getElementById . htmlUid @ Text $ txt ^. # uniqueUid
253
+ el <- getElementById . htmlUid @ MisoString $ txt ^. # uniqueUid
253
254
elExist <- ghcjsPure $ JS. isTruthy el
254
255
when elExist $ do
255
- inps <- el ^. JS. js1 (" getElementsByTagName" :: Text ) (" input" :: Text )
256
+ inps <-
257
+ el ^. JS. js1 (" getElementsByTagName" :: MisoString ) (" input" :: MisoString )
256
258
inp <- inps !! 0
257
- act <- JS. global ! (" document" :: Text ) ! (" activeElement" :: Text )
259
+ act <- JS. global ! (" document" :: MisoString ) ! (" activeElement" :: MisoString )
258
260
elActive <- JS. strictEqual inp act
259
- unless elActive $ el ^. JS. jss (" value" :: Text ) (txt ^. # uniqueValue)
261
+ unless elActive $ el ^. JS. jss (" value" :: MisoString ) (txt ^. # uniqueValue)
260
262
pure txt
261
263
262
264
evalModel :: (MonadThrow m , MonadUnliftIO m ) => Model -> m Model
@@ -362,32 +364,3 @@ upToDate lhs rhs =
362
364
diff < 3600
363
365
where
364
366
diff = abs . toRational $ diffUTCTime lhs rhs
365
-
366
- log :: (Show a , Data a ) => a -> JSM ()
367
- log = consoleLog . inspectMiso
368
-
369
- insertCurrentUri :: Model -> JSM ()
370
- insertCurrentUri st = do
371
- uri <- URI. mkURI $ shareLink (st ^. # modelState . # stScreen) st
372
- void
373
- $ JS. global
374
- ^. JS. js2 (" insertStorage" :: Text ) (" current-" <> vsn) (ms $ URI. render uri)
375
-
376
- selectCurrentUri :: (Maybe URI. URI -> JSM () ) -> JSM ()
377
- selectCurrentUri after = do
378
- success <- JS. function $ \ _ _ ->
379
- handleAny (\ e -> log e >> after Nothing ) . \ case
380
- [val] -> do
381
- valExist <- ghcjsPure $ JS. isTruthy val
382
- if not valExist
383
- then after Nothing
384
- else do
385
- raw <- JS. fromJSVal @ Text val
386
- str <- maybe (throwString @ Text " Storage bad type!" ) pure raw
387
- uri <- URI. mkURI $ fromMisoString str
388
- after $ Just uri
389
- _ ->
390
- throwString @ Text " Storage bad argv!"
391
- failure <- JS. function $ \ _ _ _ -> log @ Text " Storage reader failure!"
392
- prom <- JS. global ^. JS. js1 (" selectStorage" :: Text ) (" current-" <> vsn)
393
- void $ prom ^. JS. js2 (" then" :: Text ) success failure
0 commit comments