Skip to content

Instantly share code, notes, and snippets.

@dmsnell
Last active May 26, 2017 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmsnell/25137286c5c456f1907c1d6ac7da3762 to your computer and use it in GitHub Desktop.
Save dmsnell/25137286c5c456f1907c1d6ac7da3762 to your computer and use it in GitHub Desktop.
Building a description of the Comment object in Calypso
module Main where
import Prelude
import Data.Foldable (fold)
import Data.Generic
import Data.Maybe
import TryPureScript
data CommentId = CommentId Int
type DateTime = String {- this interactive editor doesn't have the right type -}
type Email = String
data PostId = PostId Int
data SiteId = SiteId Int
type URL = String
type UserId = Int
data AnonymousUserInfo = AnonymousUserInfo
{ avatar :: Maybe URL
, displayName :: String
, email :: Maybe Email
, url :: Maybe URL
}
data CommentStatus = Approved | Pending | Spam | Trash
data CommentInfo = CommentInfo
{ content :: String
, createdAt :: DateTime
, isLiked :: Boolean
, parentId :: Maybe CommentId
, replyId :: Maybe CommentId
, status :: CommentStatus
}
data CommentAuthor
= AnonymousUser AnonymousUserInfo
| WordPressUser UserId
data Comment
= Loading SiteId CommentId
| Comment SiteId PostId CommentId CommentAuthor CommentInfo
main =
render $ fold
[ p (text "Hi")
, p (text $ show $ Loading (SiteId 5) (CommentId 8))
, p (text $ show $ Comment (SiteId 5) (PostId 3) (CommentId 1) (WordPressUser 14) aComment)
, p (text $ show $ Comment (SiteId 5) (PostId 3) (CommentId 12) (AnonymousUser aUser) aComment)
, p (text $ show $ Comment (SiteId 5) (PostId 3) (CommentId 9) (WordPressUser 28) bComment)
]
where
aComment = CommentInfo
{ content: "WordPress is the press-test"
, createdAt: "2017-05-26 14:52:14 +0000" {- should be actual time -}
, isLiked: false
, parentId: Nothing
, replyId: Just (CommentId 9)
, status: Pending
}
bComment = CommentInfo
{ content: "You know it!"
, createdAt: "2017-05-26 14:56:42 +0000" {- should be actual time -}
, isLiked: true
, parentId: Just (CommentId 1)
, replyId: Nothing
, status: Approved
}
aUser = AnonymousUserInfo
{ avatar: Nothing
, displayName: "Blake Stone"
, email: Just "blake@sto.ne"
, url: Nothing
}
derive instance genericCommentId :: Generic CommentId
derive instance genericPostId :: Generic PostId
derive instance genericSiteId :: Generic SiteId
derive instance genericAnonymousUserInfo :: Generic AnonymousUserInfo
derive instance genericComment :: Generic Comment
derive instance genericCommentAuthor :: Generic CommentAuthor
derive instance genericCommentInfo :: Generic CommentInfo
derive instance genericCommentStatus :: Generic CommentStatus
instance showCommentId :: Show CommentId where
show = gShow
instance showPostId :: Show PostId where
show = gShow
instance showSiteId :: Show SiteId where
show = gShow
instance showAnonymousUserInfo :: Show AnonymousUserInfo where
show = gShow
instance showCommentAuthor :: Show CommentAuthor where
show = gShow
instance showComment :: Show Comment where
show = gShow
instance showCommentInfo :: Show CommentInfo where
show = gShow
instance showCommentStatus :: Show CommentStatus where
show = gShow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment