@@ -1,13 +1,12 @@
1−module Yoga.InlineCode.Stories where
1+module Yoga.Layer.Stories where
3import Prelude hiding (add)
3import Prelude hiding (add)
4−import Data.Array (intercalate, length)
4+import Data.Array (intercalate)
5import Data.Either (Either(..))
5import Data.Either (Either(..))
6import Data.Maybe (Maybe(..))
6import Data.Maybe (Maybe(..))
7−import Data.String (Pattern(..), split, trim)
7+import Data.String (Pattern(..), split)
8import Data.String.CodeUnits as String
8import Data.String.CodeUnits as String
9import Data.Tuple.Nested ((/\))
9import Data.Tuple.Nested ((/\))
10−import Debug.Trace (spy)
11import Effect (Effect)
10import Effect (Effect)
12import Effect.Aff (Aff)
11import Effect.Aff (Aff)
13import Effect.Class.Console (log)
12import Effect.Class.Console (log)
@@ -16,46 +15,45 @@ import Milkis as M
16import Milkis.Impl.Window (windowFetch)
15import Milkis.Impl.Window (windowFetch)
17import React.Basic (JSX, fragment)
16import React.Basic (JSX, fragment)
18import React.Basic.DOM as R
17import React.Basic.DOM as R
19−import React.Basic.Extra.Hooks (useAffReducer)
18+import React.Basic.Extra.Hooks.UseAffReducer (useAffReducer)
20−import React.Basic.Helpers (jsx)
21import React.Basic.Hooks (ReactComponent, component, element)
19import React.Basic.Hooks (ReactComponent, component, element)
22import React.Basic.Hooks as React
20import React.Basic.Hooks as React
23import Storybook.Decorator.FullScreen (fullScreenDecorator)
21import Storybook.Decorator.FullScreen (fullScreenDecorator)
24import Storybook.React (Storybook, add, addDecorator, storiesOf)
22import Storybook.React (Storybook, add, addDecorator, storiesOf)
25import Yoga.CompileEditor.Component (compileAndRun)
23import Yoga.CompileEditor.Component (compileAndRun)
26−import Yoga.InlineCode.Component (Action(..))
24+import Yoga.Layer.Component (Action(..))
27−import Yoga.InlineCode.Component as InlineCode
25+import Yoga.Layer.Component as Layer
28import Yoga.Modal.Component as Modal
26import Yoga.Modal.Component as Modal
30stories ∷ Effect Storybook
28stories ∷ Effect Storybook
31stories = do
29stories = do
32− storiesOf "InlineCode" do
30+ storiesOf "Layer" do
33 addDecorator fullScreenDecorator
31 addDecorator fullScreenDecorator
34− add "The InlineCode" InlineCode.makeComponent
32+ add "The Layer" Layer.makeComponent
35 [ ( justifill
33 [ ( justifill
36− { dispatch: \(_ ∷ InlineCode.Action) -> ((log "hi") ∷ Effect Unit)
34+ { dispatch: \(_ ∷ Layer.Action) -> ((log "hi") ∷ Effect Unit)
40− add "The InlineCode with some context" mkWrapper
38+ add "The Layer with some context" mkWrapper
41 [ { inside:
39 [ { inside:
42 \inlineCode ->
40 \inlineCode ->
43 [ R.text "hi!"
41 [ R.text "hi!"
44− , element inlineCode (justifill { dispatch: \(_ ∷ InlineCode.Action) -> (log "Hi") ∷ Effect Unit })
42+ , element inlineCode (justifill { dispatch: \(_ ∷ Layer.Action) -> (log "Hi") ∷ Effect Unit })
45 , R.text "hello again!"
43 , R.text "hello again!"
49− add "The InlineCode with some code" mkWrapper
47+ add "The Layer with some code" mkWrapper
50 [ { inside:
48 [ { inside:
51 \inlineCode ->
49 \inlineCode ->
52 [ R.code_ [ R.text "main = logShow \"" ]
50 [ R.code_ [ R.text "main = logShow \"" ]
53− , element inlineCode (justifill { dispatch: \(_ ∷ InlineCode.Action) -> (log "Hi") ∷ Effect Unit })
51+ , element inlineCode (justifill { dispatch: \(_ ∷ Layer.Action) -> (log "Hi") ∷ Effect Unit })
54 , R.code_ [ R.text "\"" ]
52 , R.code_ [ R.text "\"" ]
58− add "The InlineCode with some real code" mkRealWrapper
56+ add "The Layer with some real code" mkRealWrapper
61codePrefix =
59codePrefix =
@@ -71,10 +69,10 @@ renderCode c = intercalate [ R.br {} ] (toJSX <$> lines)
71 toJSX line = [ R.code_ [ R.text line ] ]
69 toJSX line = [ R.code_ [ R.text line ] ]
72 lines = split (Pattern "\n") c
70 lines = split (Pattern "\n") c
74−mkWrapper ∷ Effect (ReactComponent { inside ∷ ReactComponent InlineCode.Props -> Array JSX })
72+mkWrapper ∷ Effect (ReactComponent { inside ∷ ReactComponent Layer.Props -> Array JSX })
75mkWrapper = do
73mkWrapper = do
76− inlineCode <- InlineCode.makeComponent
74+ inlineCode <- Layer.makeComponent
77− component "InlineCodeWrapper" \{ inside } -> React.do
75+ component "LayerWrapper" \{ inside } -> React.do
79 $ R.div_ (inside inlineCode)
77 $ R.div_ (inside inlineCode)
@@ -82,21 +80,21 @@ type State
82 = Maybe Boolean
80 = Maybe Boolean
84data RealAction
82data RealAction
85− = InlineCodeAction InlineCode.Action
83+ = LayerAction Layer.Action
86 | CloseModal
84 | CloseModal
88derive instance eqRealAction ∷ Eq RealAction
86derive instance eqRealAction ∷ Eq RealAction
89mkRealWrapper ∷ Effect (ReactComponent {})
87mkRealWrapper ∷ Effect (ReactComponent {})
90mkRealWrapper = do
88mkRealWrapper = do
91− inlineCode <- InlineCode.makeComponent
89+ inlineCode <- Layer.makeComponent
92 modal <- Modal.makeComponent
90 modal <- Modal.makeComponent
93− component "InlineCodeWrapper" \{} -> React.do
91+ component "LayerWrapper" \{} -> React.do
94 state /\ dispatch <- useAffReducer Nothing realReducer
92 state /\ dispatch <- useAffReducer Nothing realReducer
97 [ R.h2_ [ R.text "Let's log some 'Magick'" ]
95 [ R.h2_ [ R.text "Let's log some 'Magick'" ]
98 , fragment $ renderCode codePrefix
96 , fragment $ renderCode codePrefix
99− , element inlineCode (justifill { dispatch: dispatch <<< InlineCodeAction, width: String.length "Magick" })
97+ , element inlineCode (justifill { dispatch: dispatch <<< LayerAction, width: String.length "Magick" })
100 , fragment $ renderCode codeSuffix
98 , fragment $ renderCode codeSuffix
101 , R.br {}
99 , R.br {}
102 , case state of
100 , case state of
@@ -108,9 +106,9 @@ mkRealWrapper = do
108realReducer ∷ State -> RealAction -> Aff State
106realReducer ∷ State -> RealAction -> Aff State
109realReducer state = case _ of
107realReducer state = case _ of
110 CloseModal -> pure Nothing
108 CloseModal -> pure Nothing
111− InlineCodeAction (CompileAndRunCode code) -> do
109+ LayerAction (CompileAndRunCode code) -> do
112 res <- compileAndRun (M.fetch windowFetch) { code: codePrefix <> code <> codeSuffix }
110 res <- compileAndRun (M.fetch windowFetch) { code: codePrefix <> code <> codeSuffix }
113− (pure <<< Just) case spy "res" res of
111+ (pure <<< pure) case res of
114 Right { stdout }
112 Right { stdout }
115 | String.dropRight 1 stdout == "Magick" -> true
113 | String.dropRight 1 stdout == "Magick" -> true
116 _ -> false
114 _ -> false