From b2eab5fe800c0b0fb7282629b8eed4105d076a60 Mon Sep 17 00:00:00 2001 From: "code@dmj.io" Date: Mon, 1 Sep 2025 13:02:52 -0500 Subject: [PATCH 1/5] Bump flake, use LambdaCase, newFileReader --- cabal.project | 2 +- flake.lock | 18 +++++++++--------- src/Main.hs | 36 ++++++++++++++++++++---------------- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/cabal.project b/cabal.project index ef72d91..730b220 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: f90bda01c396f058bfe42d0cecb4ba776160a953 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..33b44df 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 #-} @@ -25,7 +26,7 @@ import Miso hiding ((<#)) import qualified Miso 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 +86,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 From 2252786c95d375a61b5f04ad0c29b4d227f43c14 Mon Sep 17 00:00:00 2001 From: "David M. Johnson" <875324+dmjio@users.noreply.github.com> Date: Mon, 1 Sep 2025 13:07:44 -0500 Subject: [PATCH 2/5] Update git tag for miso repository --- cabal.project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal.project b/cabal.project index 730b220..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: f90bda01c396f058bfe42d0cecb4ba776160a953 + tag: d75ab7cbe3e2f8b0ea0294a57ee8dc3bdd9389ac From a6d564de54b7bdc592e9ff245767d0a9e87b5f36 Mon Sep 17 00:00:00 2001 From: "David M. Johnson" <875324+dmjio@users.noreply.github.com> Date: Mon, 1 Sep 2025 13:24:28 -0500 Subject: [PATCH 3/5] Refactor ReadFile action to use do notation --- src/Main.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.hs b/src/Main.hs index 33b44df..7f8f2ae 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -87,7 +87,7 @@ app = (component (Model mempty) updateModel viewModel) -- | Update function updateModel :: Action -> Transition Model Action updateModel = \case - ReadFile input -> + ReadFile input -> do M.withSink $ \sink -> do files_ <- files input reader <- newFileReader From 732ab40228912d8022e52db8427c9c6c37f0f651 Mon Sep 17 00:00:00 2001 From: "David M. Johnson" <875324+dmjio@users.noreply.github.com> Date: Mon, 1 Sep 2025 13:43:44 -0500 Subject: [PATCH 4/5] Import additional Miso.Html modules --- src/Main.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Main.hs b/src/Main.hs index 7f8f2ae..1ea308d 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -24,6 +24,8 @@ 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 Miso.Lens ((.=), Lens, lens) import Miso.String (MisoString, unlines, null) import qualified Miso.CSS as CSS From f9ce0d07a0000bc9f4cbf444a0ae9239f4e91c6b Mon Sep 17 00:00:00 2001 From: dmjio Date: Mon, 1 Sep 2025 15:00:48 -0500 Subject: [PATCH 5/5] dedent --- src/Main.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 1ea308d..1ede7e6 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -26,6 +26,7 @@ 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.CSS as CSS @@ -89,7 +90,7 @@ app = (component (Model mempty) updateModel viewModel) -- | Update function updateModel :: Action -> Transition Model Action updateModel = \case - ReadFile input -> do + ReadFile input -> M.withSink $ \sink -> do files_ <- files input reader <- newFileReader @@ -97,9 +98,9 @@ updateModel = \case 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] + case files_ of + [] -> consoleLog "No file specified" + file : _ -> void $ reader # ("readAsText" :: MisoString) $ [file] SetContent c -> info .= c ClickInput button ->