diff --git a/marlowe-playground-client/src/GistButtons.purs b/marlowe-playground-client/src/GistButtons.purs index 326b1123b42..6aef5e5cadc 100644 --- a/marlowe-playground-client/src/GistButtons.purs +++ b/marlowe-playground-client/src/GistButtons.purs @@ -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) diff --git a/marlowe-playground-client/src/MainFrame/State.purs b/marlowe-playground-client/src/MainFrame/State.purs index b0efa575509..9f666440ff0 100644 --- a/marlowe-playground-client/src/MainFrame/State.purs +++ b/marlowe-playground-client/src/MainFrame/State.purs @@ -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 diff --git a/marlowe-playground-client/src/MainFrame/Types.purs b/marlowe-playground-client/src/MainFrame/Types.purs index c177557d2e3..7bf704255d6 100644 --- a/marlowe-playground-client/src/MainFrame/Types.purs +++ b/marlowe-playground-client/src/MainFrame/Types.purs @@ -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 diff --git a/marlowe-playground-client/src/MainFrame/View.purs b/marlowe-playground-client/src/MainFrame/View.purs index 82dc359c2e8..04ae524af63 100644 --- a/marlowe-playground-client/src/MainFrame/View.purs +++ b/marlowe-playground-client/src/MainFrame/View.purs @@ -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) diff --git a/plutus-playground-client/src/MainFrame.purs b/plutus-playground-client/src/MainFrame.purs index fd92b622e3c..afc1f509dde 100644 --- a/plutus-playground-client/src/MainFrame.purs +++ b/plutus-playground-client/src/MainFrame.purs @@ -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) @@ -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) diff --git a/plutus-playground-client/src/Types.purs b/plutus-playground-client/src/Types.purs index cd20a73acf7..b4828b5a4b3 100644 --- a/plutus-playground-client/src/Types.purs +++ b/plutus-playground-client/src/Types.purs @@ -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 diff --git a/plutus-playground-client/src/View.purs b/plutus-playground-client/src/View.purs index ab1b3661f7c..5fb0b82df8c 100644 --- a/plutus-playground-client/src/View.purs +++ b/plutus-playground-client/src/View.purs @@ -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) diff --git a/plutus-playground-client/test/GistsTests.purs b/plutus-playground-client/test/GistsTests.purs index 472b0be68ba..69bb51eba27 100644 --- a/plutus-playground-client/test/GistsTests.purs +++ b/plutus-playground-client/test/GistsTests.purs @@ -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) diff --git a/plutus-playground-client/test/MainFrameTests.purs b/plutus-playground-client/test/MainFrameTests.purs index 59e18f5fa07..fd75fde3bd3 100644 --- a/plutus-playground-client/test/MainFrameTests.purs +++ b/plutus-playground-client/test/MainFrameTests.purs @@ -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) diff --git a/plutus-scb-client/src/MainFrame.purs b/plutus-scb-client/src/MainFrame.purs index 513b7a7e6b1..46932717428 100644 --- a/plutus-scb-client/src/MainFrame.purs +++ b/plutus-scb-client/src/MainFrame.purs @@ -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) diff --git a/web-common/src/Chain/Eval.purs b/web-common/src/Chain/State.purs similarity index 97% rename from web-common/src/Chain/Eval.purs rename to web-common/src/Chain/State.purs index d08d91c51a4..4bfa10bdd24 100644 --- a/web-common/src/Chain/Eval.purs +++ b/web-common/src/Chain/State.purs @@ -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) diff --git a/web-common/src/Gists/Types.purs b/web-common/src/Gists/Types.purs new file mode 100644 index 00000000000..7b54d6fdbff --- /dev/null +++ b/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 diff --git a/web-common/src/Gists.purs b/web-common/src/Gists/View.purs similarity index 85% rename from web-common/src/Gists.purs rename to web-common/src/Gists/View.purs index 0af369cc3be..d0143317957 100644 --- a/web-common/src/Gists.purs +++ b/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 @@ -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 @@ -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