module Web.View.MarketplaceDashboard.Show where import Web.Types import Generated.Types import IHP.Prelude import IHP.ViewPrelude import Web.Routes () 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} {renderTrendingSection trending}

Widget Patterns ({tshow (length patterns)})

{forEach patterns renderPatternRow} {if null patterns then noPatternsMsg else mempty}

Governance Templates ({tshow (length templates)})

{forEach templates renderTemplateRow} {if null templates then noTemplatesMsg 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.name} {tshow adopterCount} adopters
{pattern.widgetType} {maybe mempty renderPatternDesc pattern.description}
|] renderTemplateRow :: TemplateRow -> Html renderTemplateRow (template, cloneCount) = [hsx|
{template.name} {tshow cloneCount} clones
{maybe mempty renderPatternDesc template.description}
{forEach (jsonArrayTexts template.categories) renderCategoryChip}
|] 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 -> [] renderTrendingSection :: [TrendingRow] -> Html renderTrendingSection [] = mempty renderTrendingSection rows = [hsx|

Trending (last 30 days)

{forEach rows renderTrendingChip}
|] noPatternsMsg :: Html noPatternsMsg = [hsx|

No patterns match your search.

|] noTemplatesMsg :: Html noTemplatesMsg = [hsx|

No templates match your search.

|] renderPatternDesc :: Text -> Html renderPatternDesc d = [hsx|

{d}

|] renderCategoryChip :: Text -> Html renderCategoryChip c = [hsx|{c}|] renderWtOption :: Maybe Text -> (Text, Text) -> Html renderWtOption mWType (n, l) = [hsx||]