module Web.View.MarketplaceDashboard.Show where
import Web.Types
import Generated.Types
import IHP.Prelude
import IHP.ViewPrelude
import Data.Aeson (Value(..), decode, encode)
import qualified Data.ByteString.Lazy.Char8 as BL
type PatternRow = (WidgetPattern, Int) -- pattern + adopter_count
type TemplateRow = (GovernanceTemplate, Int) -- template + clone_count
type TrendingRow = (Id WidgetPattern, Text, Text, Int) -- id, name, widget_type, recent_adoptions
data ShowView = ShowView
{ patterns :: ![PatternRow]
, templates :: ![TemplateRow]
, trending :: ![TrendingRow]
, widgetTypeOptions :: ![(Text, Text)] -- (name, label)
, searchQuery :: !(Maybe Text)
, selectedType :: !(Maybe Text)
, sortOrder :: !Text
}
instance View ShowView where
html ShowView { .. } = [hsx|
Marketplace
Discover and adopt reusable widget patterns and governance templates.
Hub Registry →
{searchBar searchQuery selectedType sortOrder widgetTypeOptions}
{if not (null trending)
then [hsx|
Trending (last 30 days)
{forEach trending renderTrendingChip}
|]
else mempty}
Widget Patterns
({tshow (length patterns)})
{forEach patterns renderPatternRow}
{if null patterns
then [hsx|
No patterns match your search.
|]
else mempty}
Governance Templates
({tshow (length templates)})
{forEach templates renderTemplateRow}
{if null templates
then [hsx|
No templates match your search.
|]
else mempty}
|]
searchBar :: Maybe Text -> Maybe Text -> Text -> [(Text, Text)] -> Html
searchBar mSearch mWType sortOrder wtOptions = [hsx|
|]
renderPatternRow :: PatternRow -> Html
renderPatternRow (pattern, adopterCount) = [hsx|
{pattern.widgetType}
{maybe mempty (\d -> [hsx|
{d}
|]) pattern.description}
|]
renderTemplateRow :: TemplateRow -> Html
renderTemplateRow (template, cloneCount) = [hsx|
{maybe mempty (\d -> [hsx|
{d}
|]) template.description}
{forEach (jsonArrayTexts template.categories) (\c -> [hsx|
{c}
|])}
|]
renderTrendingChip :: TrendingRow -> Html
renderTrendingChip (patternId, name, widgetType, count) = [hsx|
{name}
{widgetType}
{tshow count} adoptions
|]
jsonArrayTexts :: Value -> [Text]
jsonArrayTexts val = case decode (encode val) of
Just (arr :: [Text]) -> arr
Nothing -> []