Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ flags: +template-haskell
source-repository-package
type: git
location: https://github.com/dmjio/miso
tag: 8c4b85e6e1279bec9b66859c54f25209701b8153
tag: d75ab7cbe3e2f8b0ea0294a57ee8dc3bdd9389ac
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 23 additions & 16 deletions src/Main.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-----------------------------------------------------------------------------
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE MultilineStrings #-}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down