@@ -1,13 +1,12 @@
1−module Yoga.InlineCode.Stories where
1+module Yoga.Layer.Stories where
22
33import Prelude hiding (add)
4−import Data.Array (intercalate, length)
4+import Data.Array (intercalate)
55import Data.Either (Either(..))
66import Data.Maybe (Maybe(..))
7−import Data.String (Pattern(..), split, trim)
7+import Data.String (Pattern(..), split)
88import Data.String.CodeUnits as String
99import Data.Tuple.Nested ((/\))
10−import Debug.Trace (spy)
1110import Effect (Effect)
1211import Effect.Aff (Aff)
1312import Effect.Class.Console (log)
@@ -16,46 +15,45 @@ import Milkis as M
1615import Milkis.Impl.Window (windowFetch)
1716import React.Basic (JSX, fragment)
1817import React.Basic.DOM as R
19−import React.Basic.Extra.Hooks (useAffReducer)
20−import React.Basic.Helpers (jsx)
18+import React.Basic.Extra.Hooks.UseAffReducer (useAffReducer)
2119import React.Basic.Hooks (ReactComponent, component, element)
2220import React.Basic.Hooks as React
2321import Storybook.Decorator.FullScreen (fullScreenDecorator)
2422import Storybook.React (Storybook, add, addDecorator, storiesOf)
2523import Yoga.CompileEditor.Component (compileAndRun)
26−import Yoga.InlineCode.Component (Action(..))
27−import Yoga.InlineCode.Component as InlineCode
24+import Yoga.Layer.Component (Action(..))
25+import Yoga.Layer.Component as Layer
2826import Yoga.Modal.Component as Modal
2927
3028stories ∷ Effect Storybook
3129stories = do
32− storiesOf "InlineCode" do
30+ storiesOf "Layer" do
3331 addDecorator fullScreenDecorator
34− add "The InlineCode" InlineCode.makeComponent
32+ add "The Layer" Layer.makeComponent
3533 [ ( justifill
36− { dispatch: \(_ ∷ InlineCode.Action) -> ((log "hi") ∷ Effect Unit)
34+ { dispatch: \(_ ∷ Layer.Action) -> ((log "hi") ∷ Effect Unit)
3735 }
3836 )
3937 ]
40− add "The InlineCode with some context" mkWrapper
38+ add "The Layer with some context" mkWrapper
4139 [ { inside:
4240 \inlineCode ->
4341 [ 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 })
4543 , R.text "hello again!"
4644 ]
4745 }
4846 ]
49− add "The InlineCode with some code" mkWrapper
47+ add "The Layer with some code" mkWrapper
5048 [ { inside:
5149 \inlineCode ->
5250 [ 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 })
5452 , R.code_ [ R.text "\"" ]
5553 ]
5654 }
5755 ]
58− add "The InlineCode with some real code" mkRealWrapper
56+ add "The Layer with some real code" mkRealWrapper
5957 [ {} ]
6058
6159codePrefix =
@@ -71,10 +69,10 @@ renderCode c = intercalate [ R.br {} ] (toJSX <$> lines)
7169 toJSX line = [ R.code_ [ R.text line ] ]
7270 lines = split (Pattern "\n") c
7371
74−mkWrapper ∷ Effect (ReactComponent { inside ∷ ReactComponent InlineCode.Props -> Array JSX })
72+mkWrapper ∷ Effect (ReactComponent { inside ∷ ReactComponent Layer.Props -> Array JSX })
7573mkWrapper = do
76− inlineCode <- InlineCode.makeComponent
77− component "InlineCodeWrapper" \{ inside } -> React.do
74+ inlineCode <- Layer.makeComponent
75+ component "LayerWrapper" \{ inside } -> React.do
7876 pure
7977 $ R.div_ (inside inlineCode)
8078
@@ -82,21 +80,21 @@ type State
8280 = Maybe Boolean
8381
8482data RealAction
85− = InlineCodeAction InlineCode.Action
83+ = LayerAction Layer.Action
8684 | CloseModal
8785
8886derive instance eqRealAction ∷ Eq RealAction
8987mkRealWrapper ∷ Effect (ReactComponent {})
9088mkRealWrapper = do
91− inlineCode <- InlineCode.makeComponent
89+ inlineCode <- Layer.makeComponent
9290 modal <- Modal.makeComponent
93− component "InlineCodeWrapper" \{} -> React.do
91+ component "LayerWrapper" \{} -> React.do
9492 state /\ dispatch <- useAffReducer Nothing realReducer
9593 pure
9694 $ R.div_
9795 [ R.h2_ [ R.text "Let's log some 'Magick'" ]
9896 , 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" })
10098 , fragment $ renderCode codeSuffix
10199 , R.br {}
102100 , case state of
@@ -108,9 +106,9 @@ mkRealWrapper = do
108106realReducer ∷ State -> RealAction -> Aff State
109107realReducer state = case _ of
110108 CloseModal -> pure Nothing
111− InlineCodeAction (CompileAndRunCode code) -> do
109+ LayerAction (CompileAndRunCode code) -> do
112110 res <- compileAndRun (M.fetch windowFetch) { code: codePrefix <> code <> codeSuffix }
113− (pure <<< Just) case spy "res" res of
111+ (pure <<< pure) case res of
114112 Right { stdout }
115113 | String.dropRight 1 stdout == "Magick" -> true
116114 _ -> false