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
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ name: Build and deploy
on:
push:
branches: main
pull_request:

permissions:
contents: read
Expand Down
18 changes: 8 additions & 10 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,18 @@ app = (component (Model mempty) updateModel viewModel)
----------------------------------------------------------------------------
-- | Update function
updateModel :: Action -> Effect Model Action
updateModel (ReadFile fileReaderInput) = io $ do
file <- fileReaderInput ! ("files" :: String) !! 0
reader <- J.new (J.jsg ("FileReader" :: String)) ([] :: [JSVal])
mvar <- liftIO newEmptyMVar
(reader <# ("onload" :: String)) =<< do
updateModel (ReadFile fileReaderInput) = M.withSink $ \sink -> do
file <- fileReaderInput ! ("files" :: MisoString) !! 0
reader <- J.new (J.jsg ("FileReader" :: MisoString)) ([] :: [JSVal])
(reader <# ("onload" :: MisoString)) =<< do
M.asyncCallback $ do
result <- J.fromJSValUnchecked =<< reader ! ("result" :: String)
liftIO (putMVar mvar result)
void $ reader # ("readAsText" :: String) $ [file]
SetContent <$> liftIO (readMVar mvar)
result <- J.fromJSValUnchecked =<< reader ! ("result" :: MisoString)
sink (SetContent result)
void $ reader # ("readAsText" :: MisoString) $ [file]
updateModel (SetContent c) = info .= c
updateModel (ClickInput button) = io_ $ do
fileReader <- button ! ("nextSibling" :: MisoString) -- dmj: gets hidden input
void $ fileReader # ("click" :: String) $ ([] :: [JSVal])
void $ fileReader # ("click" :: MisoString) $ ([] :: [JSVal])
----------------------------------------------------------------------------
-- | View function
viewModel :: Model -> View Action
Expand Down
Loading