diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 01eeceb..006a328 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,6 +4,7 @@ name: Build and deploy on: push: branches: main + pull_request: permissions: contents: read diff --git a/src/Main.hs b/src/Main.hs index d9434cd..6cea4f3 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -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