Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
feat: mocked tutorial data
Browse files Browse the repository at this point in the history
  • Loading branch information
prescientmoon committed Jul 16, 2020
1 parent ce79ab0 commit 843cd13
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
24 changes: 23 additions & 1 deletion src/AppM.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Lunarbox.AppM where
import Prelude
import Control.Monad.Reader (class MonadAsk, class MonadReader, ReaderT, asks, runReaderT)
import Data.Argonaut (encodeJson)
import Data.Either (Either, hush)
import Data.Either (Either(..), hush)
import Data.Lens (view)
import Data.Maybe (Maybe(..))
import Effect.Aff (Aff)
Expand All @@ -18,12 +18,17 @@ import Lunarbox.Api.Request as Request
import Lunarbox.Api.Utils (authenticate, mkRawRequest, mkRequest, withBaseUrl)
import Lunarbox.Capability.Navigate (class Navigate, navigate)
import Lunarbox.Capability.Resource.Project (class ManageProjects)
import Lunarbox.Capability.Resource.Tutorial (class ManageTutorials, createTutorial)
import Lunarbox.Capability.Resource.User (class ManageUser)
import Lunarbox.Config (Config, _changeRoute, _currentUser, _userBus)
import Lunarbox.Control.Monad.Effect (printString)
import Lunarbox.Data.Editor.Node.NodeId (NodeId(..))
import Lunarbox.Data.Editor.Save (jsonToState, stateToJson)
import Lunarbox.Data.ProjectId (ProjectId)
import Lunarbox.Data.Route (routingCodec)
import Lunarbox.Data.Route as Route
import Lunarbox.Data.Tutorial (TutorialId(..))
import Record as Record
import Routing.Duplex (print)

-- Todo: better type for errors
Expand Down Expand Up @@ -89,3 +94,20 @@ instance manageProjectsAppM :: ManageProjects AppM where
saveProject id json = void <$> mkRawRequest { endpoint: Project id, method: Put $ Just json }
deleteProject id = void <$> mkRawRequest { endpoint: Project id, method: Delete }
getProjects = mkRequest { endpoint: Projects, method: Get }

instance manageTutorialsAppM :: ManageTutorials AppM where
createTutorial =
pure
$ Right
{ base: NodeId "76"
, name: "First tutorial"
, id: TutorialId "0"
, requires: []
, steps: []
, hiddenElements: []
, tests: []
}
deleteTutorial id = Right <$> printString ("Deleted id " <> show id)
saveTutorial _ = pure $ Right unit
getTutorials = pure $ Right []
getTutorial id = map (Record.merge { completed: false, id }) <$> createTutorial
6 changes: 3 additions & 3 deletions src/Capability/Resource/Tutorial.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module Lunarbox.Capability.Resource.Tutorial where
import Prelude
import Data.Either (Either)
import Halogen (HalogenM, lift)
import Lunarbox.Data.Tutorial (TutorialId, TutorialWithMetadata)
import Lunarbox.Data.Tutorial (TutorialId, TutorialWithMetadata, Tutorial)

-- | Capability for managing projects
class
Monad m <= ManageTutorials m where
createTutorial :: m (Either String TutorialWithMetadata)
createTutorial :: m (Either String (Tutorial ()))
deleteTutorial :: TutorialId -> m (Either String Unit)
saveTutorial :: TutorialWithMetadata -> m (Either String Unit)
saveTutorial :: Tutorial () -> m (Either String Unit)
getTutorials :: m (Either String (Array TutorialWithMetadata))
getTutorial :: TutorialId -> m (Either String TutorialWithMetadata)

Expand Down
5 changes: 4 additions & 1 deletion src/Data/Tutorial.purs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ derive newtype instance decodeJsonTutorialTest :: DecodeJson TutorialTest
newtype TutorialId
= TutorialId String

instance showTutorialId :: Show TutorialId where
show (TutorialId a) = a

derive newtype instance encodeJsonTutorialId :: EncodeJson TutorialId

derive newtype instance decodeJsonTutorialId :: DecodeJson TutorialId
Expand All @@ -66,7 +69,7 @@ type Tutorial r
}

type TutorialWithMetadata
= Tutorial ( id :: TutorialId, completed :: Boolean )
= Tutorial ( completed :: Boolean )

-- | Possible errors we can get by validating a tutorial
data TutorialValidationError
Expand Down

0 comments on commit 843cd13

Please sign in to comment.