module Web.View.Hubs.FrictionHeatmap where
import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
import Application.Helper.FrictionScore (scoreBand)
data FrictionHeatmapView = FrictionHeatmapView
{ hub :: !Hub
, widgets :: ![Widget]
, frictionScores :: ![FrictionScore]
}
instance View FrictionHeatmapView where
html FrictionHeatmapView { .. } = [hsx|
Friction Heatmap
{hub.name}
Low (0–19)
Medium (20–39)
High (40–59)
Critical (60+)
{if null widgets
then [hsx|No widgets in this hub.
|]
else [hsx|
{forEach widgets renderWidgetCard}
|]}
|]
where
scoreFor w = maybe 0 (.score) (find (\fs -> fs.widgetId == w.id) frictionScores)
hasScore w = any (\fs -> fs.widgetId == w.id) frictionScores
renderWidgetCard :: Widget -> Html
renderWidgetCard w =
let s = scoreFor w
band = scoreBand s
in [hsx|
band}>
{w.name}
{if hasScore w
then [hsx|
{show s}|]
else [hsx|
–|]}
{w.widgetType}
|]