git.iko.soy/rowtype-yoga/psfp
on master help sign in
fewer stars
b360daeMark Eibes
client/src/CompileEditor/Component.purs+21−21
@@ -1,14 +1,17 @@
1module CompileEditor.Component where
1module CompileEditor.Component where
2
2
3import Prelude hiding (add)
3import Prelude hiding (add)
4+
4import Button.Component (ButtonType(..), mkButton)
5import Button.Component (ButtonType(..), mkButton)
5import Card.Component (mkCard)
6import Card.Component (mkCard)
7+import Data.Array (intercalate)
8+import Data.Either (Either(..))
6import Data.Foldable (for_)
9import Data.Foldable (for_)
7import Data.Nullable (null)
10import Data.Nullable (null)
8import Data.Tuple.Nested ((/\))
11import Data.Tuple.Nested ((/\))
9import Editor (getValue, mkEditor)
12import Editor (getValue, mkEditor)
10import Effect (Effect)
13import Effect (Effect)
11−import Effect.Aff (Aff, launchAff_)
14+import Effect.Aff (Aff, error, launchAff_, throwError)
12import Effect.Class (liftEffect)
15import Effect.Class (liftEffect)
13import Milkis as M
16import Milkis as M
14import Milkis.Impl.Window (windowFetch)
17import Milkis.Impl.Window (windowFetch)
@@ -36,7 +39,7 @@ mkCompileEditor = do
36 $ fragment
39 $ fragment
37 [ element button
40 [ element button
38 { buttonType: PlainButton
41 { buttonType: PlainButton
39− , children: [ R.text "Compile"]
42+ , children: [ R.text "Compile" ]
40 , buttonProps:
43 , buttonProps:
41 { onClick:
44 { onClick:
42 handler_ do
45 handler_ do
@@ -44,9 +47,10 @@ mkCompileEditor = do
44 for_ maybeEditor \ed -> do
47 for_ maybeEditor \ed -> do
45 code <- getValue ed
48 code <- getValue ed
46 launchAff_ do
49 launchAff_ do
47− res <- compile { code }
50+ res <- compileAndRun { code }
48− res2 <- run
49− setCompileResult res2.stdout # liftEffect
51+ liftEffect $ setCompileResult case res of
52+ Left cr -> (cr.result.errors <#> _.message # intercalate "/n")
53+ Right r -> r.stdout
50 }
54 }
51 }
55 }
52 , element card { children: [ R.text compileResult ] }
56 , element card { children: [ R.text compileResult ] }
@@ -56,19 +60,15 @@ mkCompileEditor = do
56fetch ∷ M.Fetch
60fetch ∷ M.Fetch
57fetch = M.fetch windowFetch
61fetch = M.fetch windowFetch
58
62
59−compile ∷ Body.CompileRequest -> Aff Body.CompileResult
63+compileAndRun :: Body.CompileRequest -> Aff (Either Body.CompileResult Body.RunResult)
60−compile body = do
64+compileAndRun body = do
65+ response <-
61− fetch (M.URL "/api/compile")
66+ fetch (M.URL "/api/compileAndRun")
62− { method: M.postMethod
67+ { method: M.postMethod
63− , body: writeJSON body
68+ , body: writeJSON body
64− , headers: M.makeHeaders { "Content-Type": "application/json" }
69+ , headers: M.makeHeaders { "Content-Type": "application/json" }
65− }
70+ }
66− >>= M.json
71+ case M.statusCode response of
72+ 200 -> M.json response >>= readAff <#> Left
67− >>= readAff
73+ 400 -> M.json response >>= readAff <#> Right
68−
74+ code -> throwError (error $ "Unexpected response code " <> show code)
69−run ∷ Aff Body.RunResult
70−run = do
71− fetch (M.URL "/api/run")
72− { method: M.postMethod }
73− >>= M.json
74− >>= readAff
client/src/SVG/Image.purs+1−1
@@ -919,7 +919,7 @@ infixr 8 zip as <%>
919stars ∷ ∀ css. String -> { twinklingStar1 ∷ String, twinklingStar2 ∷ String, twinklingStar3 ∷ String | css } -> JSX
919stars ∷ ∀ css. String -> { twinklingStar1 ∷ String, twinklingStar2 ∷ String, twinklingStar3 ∷ String | css } -> JSX
920stars className classes =
920stars className classes =
921 let
921 let
922− n = 400
922+ n = 30
923
923
924 xs = randomRs 0.0 800.0 n $ mkSeed 84
924 xs = randomRs 0.0 800.0 n $ mkSeed 84
925
925
client/stories/EditorStories.purs+1−68
@@ -2,25 +2,9 @@ module EditorStories where
2
2
3import Prelude hiding (add)
3import Prelude hiding (add)
4
4
5−import Data.Foldable (for_)
5+import CompileEditor.Component (mkCompileEditor)
6−import Data.Nullable (null)
7−import Data.Tuple.Nested ((/\))
8−import Debug.Trace (spy)
9import Decorator.FullScreen (fullScreenDecorator)
6import Decorator.FullScreen (fullScreenDecorator)
10−import Editor (getValue, mkEditor)
11import Effect (Effect)
7import Effect (Effect)
12−import Effect.Aff (Aff, launchAff_)
13−import Effect.Class (liftEffect)
14−import Milkis as M
15−import Milkis.Impl.Window (windowFetch)
16−import React.Basic (ReactComponent)
17−import React.Basic.DOM as R
18−import React.Basic.Events (handler_)
19−import React.Basic.Hooks (component, element, fragment, readRefMaybe, useRef, useState)
20−import React.Basic.Hooks as React
21−import Shared.Json (readAff)
22−import Shared.Models.Body as Body
23−import Simple.JSON (writeJSON)
24import Storybook.React (Storybook, add, addDecorator, storiesOf)
8import Storybook.React (Storybook, add, addDecorator, storiesOf)
25
9
26stories ∷ Effect Storybook
10stories ∷ Effect Storybook
@@ -30,54 +14,3 @@ stories = do
30 add "The Editor" mkCompileEditor
14 add "The Editor" mkCompileEditor
31 [ {}
15 [ {}
32 ]
16 ]
33−
34−mkCompileEditor ∷ Effect (ReactComponent {})
35−mkCompileEditor = do
36− editor <- mkEditor
37− component "StorybookEditor" \{} -> React.do
38− editorRef <- useRef null
39− compileResult /\ modifyCompileResult <- useState ""
40− let
41− setCompileResult = modifyCompileResult <<< const
42− pure
43− $ fragment
44− [ R.button
45− { children: pure $ R.text "Compile"
46− , onClick:
47− handler_ do
48− maybeEditor <- (readRefMaybe editorRef)
49− for_ maybeEditor \ed -> do
50− code <- getValue ed
51− launchAff_ do
52− res <- compile { code }
53− res2 <- run
54− setCompileResult res2.stdout # liftEffect
55−
56−
57− }
58− , R.textarea
59− { value: compileResult
60− , disabled: true
61− }
62− , element editor { editorRef }
63− ]
64−
65−fetch ∷ M.Fetch
66−fetch = M.fetch windowFetch
67−
68−compile ∷ Body.CompileRequest -> Aff Body.CompileResult
69−compile body = do
70− fetch (M.URL "/api/compile")
71− { method: M.postMethod
72− , body: spy "Body" $ writeJSON body
73− , headers: M.makeHeaders { "Content-Type": "application/json" }
74− }
75− >>= M.json
76− >>= readAff
77−
78−run ∷ Aff Body.RunResult
79−run = do
80− fetch (M.URL "/api/run")
81− { method: M.postMethod }
82− >>= M.json
83− >>= readAff