module Web.View.Annotations.Index where
import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
data IndexView = IndexView
{ widget :: !Widget
, annotations :: ![Annotation]
}
instance View IndexView where
html IndexView { .. } = [hsx|
{forEach rootAnnotations (renderAnnotation childrenOf)}
|]
where
rootAnnotations = filter (\a -> isNothing a.parentId) annotations
childrenOf parent = filter (\a -> a.parentId == Just parent.id) annotations
renderAnnotation :: (Annotation -> [Annotation]) -> Annotation -> Html
renderAnnotation childrenOf a = [hsx|
{a.category}
{a.actorType}
{if isJust a.retractedAt
then [hsx|retracted|]
else mempty}
{show a.createdAt}
{a.body}
{forEach (childrenOf a) (renderAnnotation childrenOf)}
|]