module Web.View.Annotations.Index where
import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
import Web.Routes ()
data IndexView = IndexView
{ widget :: !Widget
, annotations :: ![Annotation]
}
instance View IndexView where
html IndexView { .. } =
let rootAnnotations = filter (\a -> isNothing a.parentId) annotations
childrenOf parent = filter (\a -> a.parentId == Just parent.id) annotations
in [hsx|
{forEach rootAnnotations (renderAnnotation childrenOf)}
|]
renderAnnotation :: (Annotation -> [Annotation]) -> Annotation -> Html
renderAnnotation childrenOf a = [hsx|
{a.category}
{a.severity}
{a.actorType}
{if isJust a.retractedAt then retractedBadge else mempty}
{show a.createdAt}
{a.body}
{forEach (childrenOf a) (renderAnnotation childrenOf)}
|]
retractedBadge :: Html
retractedBadge = [hsx|retracted|]
severityClass :: Text -> Text
severityClass "low" = "text-xs px-2 py-0.5 rounded bg-gray-100 text-gray-500"
severityClass "medium" = "text-xs px-2 py-0.5 rounded bg-blue-100 text-blue-700"
severityClass "high" = "text-xs px-2 py-0.5 rounded bg-yellow-100 text-yellow-800"
severityClass "critical" = "text-xs px-2 py-0.5 rounded bg-red-100 text-red-800 font-semibold"
severityClass _ = "text-xs px-2 py-0.5 rounded bg-gray-100 text-gray-500"