| | | 1 | | using Chronicis.Shared.DTOs; |
| | | 2 | | |
| | | 3 | | namespace Chronicis.Client.Components.Articles; |
| | | 4 | | |
| | | 5 | | public sealed class WikiLinkAutocompleteItem |
| | | 6 | | { |
| | 0 | 7 | | private WikiLinkAutocompleteItem() |
| | | 8 | | { |
| | 0 | 9 | | } |
| | | 10 | | |
| | 0 | 11 | | public bool IsExternal { get; private init; } |
| | 0 | 12 | | public bool IsCategory { get; private init; } |
| | 0 | 13 | | public string Title { get; private init; } = string.Empty; |
| | 0 | 14 | | public string? SecondaryText { get; private init; } |
| | 0 | 15 | | public string? Source { get; private init; } |
| | 0 | 16 | | public Guid? ArticleId { get; private init; } |
| | 0 | 17 | | public string? ExternalId { get; private init; } |
| | 0 | 18 | | public string? CategoryKey { get; private init; } |
| | 0 | 19 | | public string? Icon { get; private init; } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// If the suggestion matched via an alias, this contains the matched alias. |
| | | 23 | | /// Used for display: "MatchedAlias (Title)" |
| | | 24 | | /// </summary> |
| | 0 | 25 | | public string? MatchedAlias { get; private init; } |
| | | 26 | | |
| | 0 | 27 | | public string SourceBadge => string.IsNullOrWhiteSpace(Source) |
| | 0 | 28 | | ? string.Empty |
| | 0 | 29 | | : Source.ToUpperInvariant(); |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Gets the display title. If matched via alias, shows "Alias (Title)". |
| | | 33 | | /// </summary> |
| | 0 | 34 | | public string DisplayTitle => !string.IsNullOrWhiteSpace(MatchedAlias) |
| | 0 | 35 | | ? $"{MatchedAlias} ({Title})" |
| | 0 | 36 | | : Title; |
| | | 37 | | |
| | | 38 | | public static WikiLinkAutocompleteItem FromInternal(LinkSuggestionDto suggestion) |
| | | 39 | | { |
| | 0 | 40 | | return new WikiLinkAutocompleteItem |
| | 0 | 41 | | { |
| | 0 | 42 | | IsExternal = false, |
| | 0 | 43 | | IsCategory = false, |
| | 0 | 44 | | Title = suggestion.Title, |
| | 0 | 45 | | SecondaryText = suggestion.DisplayPath, |
| | 0 | 46 | | ArticleId = suggestion.ArticleId, |
| | 0 | 47 | | MatchedAlias = suggestion.MatchedAlias |
| | 0 | 48 | | }; |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | public static WikiLinkAutocompleteItem FromExternal(ExternalLinkSuggestionDto suggestion) |
| | | 52 | | { |
| | 0 | 53 | | var isCategory = suggestion.Category == "_category"; |
| | | 54 | | |
| | 0 | 55 | | return new WikiLinkAutocompleteItem |
| | 0 | 56 | | { |
| | 0 | 57 | | IsExternal = true, |
| | 0 | 58 | | IsCategory = isCategory, |
| | 0 | 59 | | Title = isCategory ? $"{suggestion.Icon} {suggestion.Title}" : suggestion.Title, |
| | 0 | 60 | | SecondaryText = suggestion.Subtitle, |
| | 0 | 61 | | Source = suggestion.Source, |
| | 0 | 62 | | ExternalId = isCategory ? null : suggestion.Id, |
| | 0 | 63 | | CategoryKey = isCategory ? suggestion.Id?.Replace("_category/", "") : null, |
| | 0 | 64 | | Icon = suggestion.Icon, |
| | 0 | 65 | | MatchedAlias = null // External links don't have aliases |
| | 0 | 66 | | }; |
| | | 67 | | } |
| | | 68 | | } |