Skip to content

Commit

Permalink
Merge pull request #2486 from input-output-hk/tidy-web-common
Browse files Browse the repository at this point in the history
A little bit of web-common code tidying.
  • Loading branch information
krisajenkins committed Nov 23, 2020
2 parents 8cd06c8 + f24860d commit 7cf124f
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 41 deletions.
2 changes: 1 addition & 1 deletion marlowe-playground-client/src/GistButtons.purs
Expand Up @@ -4,7 +4,7 @@ import Prelude hiding (div)
import Auth (AuthRole(..), authStatusAuthRole)
import Data.Lens (to, view, (^.))
import Data.Maybe (Maybe(..))
import Gists (idPublishGist)
import Gists.View (idPublishGist)
import Halogen.HTML (ClassName(..), HTML, a, button, div, div_, p_, text)
import Halogen.HTML.Events (onClick)
import Halogen.HTML.Properties (class_, classes, disabled)
Expand Down
4 changes: 2 additions & 2 deletions marlowe-playground-client/src/MainFrame/State.purs
Expand Up @@ -20,8 +20,8 @@ import Effect.Class (class MonadEffect)
import Examples.Haskell.Contracts (example) as HE
import Examples.JS.Contracts (example) as JE
import Gist (Gist, _GistId, gistDescription, gistId)
import Gists (GistAction(..))
import Gists as Gists
import Gists.Types (GistAction(..))
import Gists.Types (parseGistUrl) as Gists
import Halogen (Component, liftEffect, query, subscribe')
import Halogen as H
import Halogen.ActusBlockly as ActusBlockly
Expand Down
2 changes: 1 addition & 1 deletion marlowe-playground-client/src/MainFrame/Types.purs
Expand Up @@ -14,7 +14,7 @@ import Data.Newtype (class Newtype)
import Data.Symbol (SProxy(..))
import Demos.Types as Demos
import Gist (Gist, GistId)
import Gists (GistAction)
import Gists.Types (GistAction)
import Halogen (ClassName)
import Halogen as H
import Halogen.ActusBlockly as AB
Expand Down
2 changes: 1 addition & 1 deletion marlowe-playground-client/src/MainFrame/View.purs
Expand Up @@ -6,7 +6,7 @@ import Data.Maybe (Maybe(..))
import Demos.View (render) as Demos
import Effect.Aff.Class (class MonadAff)
import GistButtons (authButton)
import Gists (GistAction(..))
import Gists.Types (GistAction(..))
import Halogen (ComponentHTML)
import Halogen.ActusBlockly as ActusBlockly
import Halogen.Blockly (blockly)
Expand Down
6 changes: 3 additions & 3 deletions plutus-playground-client/src/MainFrame.purs
Expand Up @@ -8,7 +8,7 @@ import Prelude
import AjaxUtils (renderForeignErrors)
import Analytics (Event, defaultEvent, trackEvent)
import Animation (class MonadAnimate, animate)
import Chain.Eval (handleAction) as Chain
import Chain.State (handleAction) as Chain
import Chain.Types (Action(..), AnnotatedBlockchain(..), _chainFocusAppearing)
import Chain.Types (initialState) as Chain
import Clipboard (class MonadClipboard)
Expand Down Expand Up @@ -48,8 +48,8 @@ import Effect.Class (class MonadEffect, liftEffect)
import Effect.Exception (Error, error)
import Foreign.Generic (decodeJSON)
import Gist (_GistId, gistId)
import Gists (GistAction(..))
import Gists as Gists
import Gists.Types (GistAction(..))
import Gists.Types as Gists
import Halogen (Component, hoist)
import Halogen as H
import Halogen.HTML (HTML)
Expand Down
2 changes: 1 addition & 1 deletion plutus-playground-client/src/Types.purs
Expand Up @@ -22,7 +22,7 @@ import Data.Traversable (traverse)
import Editor.Types as Editor
import Foreign.Generic (encodeJSON)
import Gist (Gist)
import Gists (GistAction)
import Gists.Types (GistAction)
import Halogen as H
import Halogen.Chartist as Chartist
import Halogen.Monaco as Monaco
Expand Down
2 changes: 1 addition & 1 deletion plutus-playground-client/src/View.purs
Expand Up @@ -14,7 +14,7 @@ import Data.Semiring (zero)
import Data.Tuple (Tuple(Tuple))
import Editor.View (compileButton, editorFeedback, editorView)
import Effect.Aff.Class (class MonadAff)
import Gists (gistControls)
import Gists.View (gistControls)
import Halogen.HTML (ClassName(ClassName), ComponentHTML, HTML, a, button, div, div_, h1, span, strong_, text)
import Halogen.HTML.Events (onClick)
import Halogen.HTML.Extra (mapComponent)
Expand Down
2 changes: 1 addition & 1 deletion plutus-playground-client/test/GistsTests.purs
Expand Up @@ -6,7 +6,7 @@ import Prelude
import Data.Either (Either(..))
import Data.Generic.Rep.Show (genericShow)
import Gist (GistId(..))
import Gists (parseGistUrl)
import Gists.Types (parseGistUrl)
import Test.Unit (TestSuite, Test, suite, test)
import TestUtils (equalWithBiformatter)

Expand Down
2 changes: 1 addition & 1 deletion plutus-playground-client/test/MainFrameTests.purs
Expand Up @@ -31,7 +31,7 @@ import Effect.Class (class MonadEffect, liftEffect)
import Effect.Exception (Error, error)
import Foreign.Generic (decodeJSON)
import Gist (Gist, GistId, gistId)
import Gists (GistAction(..))
import Gists.Types (GistAction(..))
import Halogen.Monaco (KeyBindings(..)) as Editor
import Language.Haskell.Interpreter (InterpreterError, InterpreterResult, SourceCode(..))
import MainFrame (handleAction, mkInitialState)
Expand Down
2 changes: 1 addition & 1 deletion plutus-scb-client/src/MainFrame.purs
Expand Up @@ -8,7 +8,7 @@ module MainFrame
import Prelude hiding (div)
import Animation (class MonadAnimate, animate)
import Cardano.Metadata.Types (Property, PropertyKey, Subject, SubjectProperties(..))
import Chain.Eval (handleAction) as Chain
import Chain.State (handleAction) as Chain
import Chain.Types (Action(FocusTx), AnnotatedBlockchain(..), _chainFocusAppearing)
import Chain.Types (initialState) as Chain
import Clipboard (class MonadClipboard)
Expand Down
@@ -1,4 +1,4 @@
module Chain.Eval (handleAction) where
module Chain.State (handleAction) where

import Chain.Types (Action(..), AnnotatedBlockchain, State, _chainFocus, _chainFocusAge, _findTx, _sequenceId)
import Clipboard (class MonadClipboard)
Expand Down
28 changes: 28 additions & 0 deletions web-common/src/Gists/Types.purs
@@ -0,0 +1,28 @@
module Gists.Types
( GistAction(..)
, parseGistUrl
) where

import Data.Array.NonEmpty as NonEmptyArray
import Data.Either (Either, note)
import Data.String.Regex (Regex, match, regex)
import Data.String.Regex.Flags (ignoreCase)
import Gist (GistId(..))
import Prelude (bind, ($), (<$>))

data GistAction
= PublishGist
| SetGistUrl String
| LoadGist

gistIdInLinkRegex :: Either String Regex
gistIdInLinkRegex = regex "^(.*/)?([0-9a-f]{32})$" ignoreCase

parseGistUrl :: String -> Either String GistId
parseGistUrl str = do
gistIdInLink <- gistIdInLinkRegex
note "Could not parse Gist Url"
$ do
matches <- match gistIdInLink str
match <- NonEmptyArray.index matches 2
GistId <$> match
33 changes: 6 additions & 27 deletions web-common/src/Gists.purs → web-common/src/Gists/View.purs
@@ -1,28 +1,24 @@
module Gists
( GistAction(..)
, gistControls
, parseGistUrl
module Gists.View
( gistControls
, idPublishGist
, idLoadGist
) where

import Gists.Types (GistAction(..), parseGistUrl)
import AjaxUtils (ajaxErrorPane)
import Auth (AuthRole(..), AuthStatus, authStatusAuthRole)
import Bootstrap (btn, btnBlock, btnDanger, btnInfo, btnPrimary, btnSmall, col12_, col6_, empty, formControl, isInvalid, isValid, nbsp, pullRight, row_)
import DOM.HTML.Indexed.InputType (InputType(..))
import Data.Array.NonEmpty as NonEmptyArray
import Data.Either (Either(..), isRight, note)
import Data.Lens (findOf, traversed, view)
import Data.Lens (view)
import Data.Maybe (Maybe(..), fromMaybe)
import Data.String.Regex (Regex, match, regex)
import Data.String.Regex.Flags (ignoreCase)
import Gist (Gist, GistFile, GistId(GistId), gistFileFilename, gistFiles, gistHtmlUrl)
import Gist (Gist, GistId, gistHtmlUrl)
import Halogen.HTML (ClassName(ClassName), HTML, IProp, a, button, div, div_, input, text)
import Halogen.HTML.Events (onClick, onValueInput)
import Halogen.HTML.Properties (class_, classes, disabled, href, id_, placeholder, target, type_, value)
import Icons (Icon(..), icon)
import Network.RemoteData (RemoteData(NotAsked, Loading, Failure, Success))
import Prelude (bind, const, ($), (<$>), (<<<), (<>), (=<<), (==))
import Prelude (const, ($), (<$>), (<<<), (<>), (=<<))
import Servant.PureScript.Ajax (AjaxError)

idPublishGist :: forall r i. IProp ( id :: String | r ) i
Expand All @@ -31,11 +27,6 @@ idPublishGist = id_ "publish-gist"
idLoadGist :: forall r i. IProp ( id :: String | r ) i
idLoadGist = id_ "load-gist"

data GistAction
= PublishGist
| SetGistUrl String
| LoadGist

gistControls ::
forall a p.
{ authStatus :: RemoteData AjaxError AuthStatus
Expand Down Expand Up @@ -177,15 +168,3 @@ gistPane gist =
]
[ text $ "View on Github" ]
]

gistIdInLinkRegex :: Either String Regex
gistIdInLinkRegex = regex "^(.*/)?([0-9a-f]{32})$" ignoreCase

parseGistUrl :: String -> Either String GistId
parseGistUrl str = do
gistIdInLink <- gistIdInLinkRegex
note "Could not parse Gist Url"
$ do
matches <- match gistIdInLink str
match <- NonEmptyArray.index matches 2
GistId <$> match

0 comments on commit 7cf124f

Please sign in to comment.