diff --git a/cabal.project b/cabal.project index ef72d91..afa66dd 100644 --- a/cabal.project +++ b/cabal.project @@ -9,4 +9,4 @@ flags: +template-haskell source-repository-package type: git location: https://github.com/dmjio/miso - tag: 8c4b85e6e1279bec9b66859c54f25209701b8153 + tag: d75ab7cbe3e2f8b0ea0294a57ee8dc3bdd9389ac diff --git a/flake.lock b/flake.lock index a8275ec..eac094e 100644 --- a/flake.lock +++ b/flake.lock @@ -196,11 +196,11 @@ }, "locked": { "host": "gitlab.haskell.org", - "lastModified": 1751372331, - "narHash": "sha256-1bBo0DJ8SBmKkJJAHpJedwgayvEIJK7DHrLt2bN4+q4=", + "lastModified": 1756517100, + "narHash": "sha256-7zXo0dubfvyjKarkaRRa1oxC+mhTROb0S1fSI8okYYk=", "owner": "haskell-wasm", "repo": "ghc-wasm-meta", - "rev": "7927129e42bcd6a54b9e06e26455803fa4878261", + "rev": "90725b12fb88efbad3357cace72ec77380e81a0c", "type": "gitlab" }, "original": { @@ -584,11 +584,11 @@ "servant": "servant" }, "locked": { - "lastModified": 1754249574, - "narHash": "sha256-nx5k/lCfAEYlf28CZ7u0MCjAf7iVSdBGFQEEQALDjkE=", + "lastModified": 1756636438, + "narHash": "sha256-yVVZEIGL3vHTqD8AlzxaikaRHBgJvZBhnAHyolO7eGk=", "owner": "dmjio", "repo": "miso", - "rev": "8c4b85e6e1279bec9b66859c54f25209701b8153", + "rev": "d75ab7cbe3e2f8b0ea0294a57ee8dc3bdd9389ac", "type": "github" }, "original": { @@ -599,11 +599,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1750731501, - "narHash": "sha256-Ah4qq+SbwMaGkuXCibyg+Fwn00el4KmI3XFX6htfDuk=", + "lastModified": 1755767206, + "narHash": "sha256-yi+50PemAF64H5sA4Bl3RYzz3Yniw0538SPLl3DxGU0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "69dfebb3d175bde602f612915c5576a41b18486b", + "rev": "f90bda01c396f058bfe42d0cecb4ba776160a953", "type": "github" }, "original": { diff --git a/src/Main.hs b/src/Main.hs index 0ace4bf..1ede7e6 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,6 +1,7 @@ ----------------------------------------------------------------------------- {-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE MultilineStrings #-} @@ -23,9 +24,12 @@ import Prelude hiding ((!!), null, unlines) ---------------------------------------------------------------------------- import Miso hiding ((<#)) import qualified Miso as M +import qualified Miso.Html.Property as M +import qualified Miso.Html.Element as M +import qualified Miso.Html.Event as M import Miso.Lens ((.=), Lens, lens) import Miso.String (MisoString, unlines, null) -import qualified Miso.Style as CSS +import qualified Miso.CSS as CSS ---------------------------------------------------------------------------- -- | Model newtype Model @@ -85,21 +89,24 @@ app = (component (Model mempty) updateModel viewModel) ---------------------------------------------------------------------------- -- | Update function updateModel :: Action -> Transition Model Action -updateModel (ReadFile input) = M.withSink $ \sink -> do - files_ <- files input - reader <- J.new (J.jsg ("FileReader" :: MisoString)) ([] :: [JSVal]) - (reader <# ("onload" :: MisoString)) =<< do - M.asyncCallback $ do - result <- J.fromJSValUnchecked =<< reader ! ("result" :: MisoString) - sink (SetContent result) - case files_ of - [] -> consoleLog "No file specified" - file : _ -> void $ reader # ("readAsText" :: MisoString) $ [file] -updateModel (SetContent c) = - info .= c -updateModel (ClickInput button) = io_ $ do - input <- nextSibling button - input & click () +updateModel = \case + ReadFile input -> + M.withSink $ \sink -> do + files_ <- files input + reader <- newFileReader + (reader <# ("onload" :: MisoString)) =<< do + M.asyncCallback $ do + result <- J.fromJSValUnchecked =<< reader ! ("result" :: MisoString) + sink (SetContent result) + case files_ of + [] -> consoleLog "No file specified" + file : _ -> void $ reader # ("readAsText" :: MisoString) $ [file] + SetContent c -> + info .= c + ClickInput button -> + io_ $ do + input <- nextSibling button + input & click () ---------------------------------------------------------------------------- -- | View function viewModel :: Model -> View Model Action