Skip to content

Adds longer loading screen #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 22, 2021
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ New features:

Bugfixes:
- Fixed `encode` not replacing all instances of special characters (#254 by @jy14898)
- Fixed up-to-five-second hangs between the loading icon disappearing and the content rendering (#256 @mikesol)

## [v2021-08-25.1](https://github.com/purescript/trypurescript/releases/tag/v2021-08-25.1) - 2021-08-25

Expand Down
7 changes: 4 additions & 3 deletions client/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@
$ctr.remove()
}

function setupIFrame(data) {
function setupIFrame(data, loadCb, failCb) {
var $ctr = $("#column2");
var $iframe = $(
'<iframe sandbox="allow-scripts allow-forms" id="output-iframe" src="frame.html">'
);

$ctr.empty().append($iframe);

var tries = 0;

var sendSources = setInterval(function () {
// Stop after 10 seconds
if (tries >= 100) {
Expand All @@ -47,7 +46,9 @@
var iframe = $iframe.get(0).contentWindow;
if (iframe) {
iframe.postMessage(data, "*");
loadCb();
} else {
failCb();
console.warn("Frame is not available");
}
}, 100);
Expand Down
16 changes: 11 additions & 5 deletions client/src/Try/Container.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import Data.FoldableWithIndex (foldMapWithIndex)
import Data.Maybe (Maybe(..), fromMaybe, isNothing)
import Data.Symbol (SProxy(..))
import Effect (Effect)
import Effect.Aff (Aff)
import Effect.Aff (Aff, makeAff)
import Effect.Aff as Aff
import Effect.Class.Console (error)
import Effect.Uncurried (EffectFn1, runEffectFn1)
import Effect.Uncurried (EffectFn3, runEffectFn3)
import Foreign.Object (Object)
import Foreign.Object as Object
import Halogen as H
Expand Down Expand Up @@ -85,7 +86,9 @@ _editor = SProxy
loader :: Loader
loader = makeLoader Config.loaderUrl

foreign import setupIFrame :: EffectFn1 (Object JS) Unit
type LoadCb = Effect Unit
type FailCb = Effect Unit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these type aliases are needed, but 🤷

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with them in this case because it can be otherwise difficult to tell which is the 'load' callback and which is the 'fail' callback. In other projects I also use records to help, ie. { fail :: Effect Unit, load :: Effect Unit }.

foreign import setupIFrame :: EffectFn3 (Object JS) LoadCb FailCb Unit
foreign import teardownIFrame :: Effect Unit

component :: forall q i o. H.Component HH.HTML q i o Aff
Expand Down Expand Up @@ -182,7 +185,7 @@ component = H.mkComponent
pure unit

Right (Right res@(CompileSuccess { js, warnings })) -> do
{ settings } <- H.modify _ { compiled = Just (Right res) }
{ settings } <- H.get
if settings.showJs then
H.liftEffect teardownIFrame
else do
Expand All @@ -193,7 +196,10 @@ component = H.mkComponent
pure unit
for_ mbSources \sources -> do
let eventData = Object.insert "<file>" (JS js) sources
H.liftEffect $ runEffectFn1 setupIFrame eventData
H.liftAff $ makeAff \f -> do
runEffectFn3 setupIFrame eventData (f (Right unit)) (f (Left $ Aff.error "Could not load iframe"))
mempty
H.modify_ _ { compiled = Just (Right res) }

HandleEditor (Editor.TextChanged text) -> do
_ <- H.fork $ handleAction $ Cache text
Expand Down