Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shmish111 committed Oct 23, 2020
1 parent 0276b60 commit c382829
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
28 changes: 19 additions & 9 deletions marlowe-playground-client/src/Projects/State.purs
Expand Up @@ -2,17 +2,19 @@ module Projects.State where

import Control.Monad.Except (runExceptT)
import Control.Monad.Reader (runReaderT)
import Data.Array (filter)
import Data.Bifunctor (lmap)
import Data.Array (filter, sortBy)
import Data.Bifunctor (lmap, rmap)
import Data.DateTime (DateTime)
import Data.DateTime.ISO as ISO
import Data.Either (Either(..))
import Data.Either (Either(..), hush)
import Data.Formatter.DateTime (FormatterCommand(..), format)
import Data.Lens (assign, to, view, (^.))
import Data.List (fromFoldable)
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Newtype (unwrap)
import Data.Ordering (invert)
import Effect.Aff.Class (class MonadAff)
import Gist (Gist, gistCreatedAt, gistDescription, gistId)
import Gist (Gist(..), gistDescription, gistId, gistUpdatedAt)
import Halogen (ClassName(..), ComponentHTML, HalogenM)
import Halogen.Classes (flex)
import Halogen.HTML (HTML, a, div, h1_, hr_, span, table, tbody, td, td_, text, th_, thead, tr, tr_)
Expand All @@ -22,7 +24,7 @@ import Marlowe (SPParams_, getApiGists)
import Marlowe.Gists (playgroundGist)
import Network.RemoteData (RemoteData(..))
import Network.RemoteData as RemoteData
import Prelude (Unit, Void, bind, const, discard, flip, map, mempty, pure, unit, ($), (<<<))
import Prelude (Unit, Void, bind, bottom, compare, const, discard, flip, map, mempty, pure, unit, ($), (<<<))
import Projects.Types (Action(..), Lang(..), State, _projects)
import Servant.PureScript.Ajax (errorToString)
import Servant.PureScript.Settings (SPSettings_)
Expand All @@ -37,10 +39,18 @@ handleAction ::
handleAction settings LoadProjects = do
assign _projects Loading
resp <- flip runReaderT settings $ runExceptT getApiGists
assign _projects $ lmap errorToString $ RemoteData.fromEither resp
assign _projects $ rmap sortGists $ lmap errorToString $ RemoteData.fromEither resp

handleAction settings (LoadProject lang gistId) = pure unit

sortGists :: Array Gist -> Array Gist
sortGists = sortBy f
where
dt :: String -> DateTime
dt s = fromMaybe bottom <<< map unwrap <<< hush $ runParser s ISO.parseISO

f (Gist { _gistUpdatedAt: a }) (Gist { _gistUpdatedAt: b }) = invert $ compare (dt a) (dt b)

render ::
forall m.
MonadAff m =>
Expand Down Expand Up @@ -72,7 +82,7 @@ gistsTable gists =
[ thead []
[ tr_
[ th_ [ text "Name" ]
, th_ [ text "Created" ]
, th_ [ text "Last Updated" ]
, th_ [ text "Open" ]
]
]
Expand Down Expand Up @@ -105,7 +115,7 @@ gistRow ::
gistRow gist =
tr []
[ td_ [ gist ^. (gistDescription <<< to text) ]
, td [ class_ (ClassName "date") ] [ gist ^. (gistCreatedAt <<< to formatDate <<< to text) ]
, td [ class_ (ClassName "date") ] [ gist ^. (gistUpdatedAt <<< to formatDate <<< to text) ]
, td_
[ div [ classes [ flex, ClassName "language-links" ] ]
[ a [ onClick (const <<< Just $ LoadProject Haskell (gist ^. gistId)) ] [ text "Haskell" ]
Expand Down
15 changes: 15 additions & 0 deletions marlowe-playground-server/contracts/Example.hs
@@ -0,0 +1,15 @@
{-# LANGUAGE OverloadedStrings #-}
module Example where

import Language.Marlowe

main :: IO ()
main = print . pretty $ contract


{- Define a contract, Close is the simplest contract which just ends the contract straight away
-}

contract :: Contract

contract = Close

0 comments on commit c382829

Please sign in to comment.