From ddcd982225d1b6a9e855a77a094b41fa67209b49 Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Tue, 20 Jan 2026 21:25:40 +0100 Subject: [PATCH] Update AliasVault.Client to use generic item type icons (#1465) --- .../Main/Components/Items/ItemIcon.razor | 87 +++++-------------- .../AliasClientDb/Models/ItemTypeIcons.cs | 33 +++++++ 2 files changed, 55 insertions(+), 65 deletions(-) create mode 100644 apps/server/Databases/AliasClientDb/Models/ItemTypeIcons.cs diff --git a/apps/server/AliasVault.Client/Main/Components/Items/ItemIcon.razor b/apps/server/AliasVault.Client/Main/Components/Items/ItemIcon.razor index 2d686285c..e7c506218 100644 --- a/apps/server/AliasVault.Client/Main/Components/Items/ItemIcon.razor +++ b/apps/server/AliasVault.Client/Main/Components/Items/ItemIcon.razor @@ -4,69 +4,20 @@ @using ItemTypeClass = AliasClientDb.Models.ItemType @* ItemIcon component - displays contextually appropriate icons based on item type *@ +@* Uses centralized ItemTypeIcons for SVG definitions (auto-generated from core/models) *@ @* For Login/Alias: Uses the Logo field if available, falls back to key placeholder *@ @* For CreditCard: Shows card brand icons (Visa, MC, Amex, Discover) based on card number *@ @* For Note: Shows a document/note icon *@ @if (ItemType == ItemTypeClass.Note) { - @* Note icon - document style *@ - - - - - - - + @* Note icon - using centralized definition *@ + @((MarkupString)ItemTypeIcons.Note) } else if (ItemType == ItemTypeClass.CreditCard) { - @* Credit card icon - detect brand and show appropriate icon *@ - @switch (CardBrandDetector.Detect(CardNumber)) - { - case CardBrandDetector.CardBrand.Visa: - @* Visa card icon *@ - - - - - break; - case CardBrandDetector.CardBrand.Mastercard: - @* Mastercard icon *@ - - - - - - - break; - case CardBrandDetector.CardBrand.Amex: - @* Amex card icon *@ - - - AMEX - - break; - case CardBrandDetector.CardBrand.Discover: - @* Discover card icon *@ - - - - - - - - break; - default: - @* Generic credit card icon *@ - - - - - - - break; - } + @* Credit card icon - detect brand and show appropriate icon from centralized definitions *@ + @((MarkupString)GetCardIconSvg()) } else if (Logo != null && Logo.Length > 0) { @@ -76,17 +27,7 @@ else if (Logo != null && Logo.Length > 0) else { @* Default placeholder - key icon for Login/Alias without logo *@ - - @* Key bow (circular head) - positioned top-left *@ - - @* Key hole in bow *@ - - @* Key shaft - diagonal *@ - - @* Key teeth - perpendicular to shaft *@ - - - + @((MarkupString)ItemTypeIcons.Placeholder) } @code { @@ -147,4 +88,20 @@ else ShowPlaceholder = true; StateHasChanged(); } + + /// + /// Gets the appropriate card icon SVG based on the card brand. + /// Uses centralized ItemTypeIcons definitions. + /// + private string GetCardIconSvg() + { + return CardBrandDetector.Detect(CardNumber) switch + { + CardBrandDetector.CardBrand.Visa => ItemTypeIcons.Visa, + CardBrandDetector.CardBrand.Mastercard => ItemTypeIcons.Mastercard, + CardBrandDetector.CardBrand.Amex => ItemTypeIcons.Amex, + CardBrandDetector.CardBrand.Discover => ItemTypeIcons.Discover, + _ => ItemTypeIcons.CreditCard, + }; + } } diff --git a/apps/server/Databases/AliasClientDb/Models/ItemTypeIcons.cs b/apps/server/Databases/AliasClientDb/Models/ItemTypeIcons.cs new file mode 100644 index 000000000..a563644b2 --- /dev/null +++ b/apps/server/Databases/AliasClientDb/Models/ItemTypeIcons.cs @@ -0,0 +1,33 @@ +// +// This file is auto-generated from core/models/src/icons/ItemTypeIcons.ts +// Do not edit this file directly. Run 'npm run generate:models' to regenerate. + +namespace AliasClientDb.Models; + +/// +/// Centralized SVG icon definitions for item types. +/// Single source of truth for all item type icons across platforms. +/// +public static class ItemTypeIcons +{ + /// Placeholder icon SVG. + public const string Placeholder = "\n \n \n \n \n \n"; + + /// Note icon SVG. + public const string Note = "\n \n \n \n \n \n"; + + /// CreditCard icon SVG. + public const string CreditCard = "\n \n \n \n \n"; + + /// Visa icon SVG. + public const string Visa = "\n \n \n"; + + /// Mastercard icon SVG. + public const string Mastercard = "\n \n \n \n \n"; + + /// Amex icon SVG. + public const string Amex = "\n \n AMEX\n"; + + /// Discover icon SVG. + public const string Discover = "\n \n \n \n \n \n"; +}