|
| 1 | +@using Microsoft.AspNetCore.Components.Web; |
| 2 | +@inject ITagQueryService TagQueryService |
| 3 | +@inject IOptions<ApplicationConfiguration> AppConfiguration |
| 4 | +@inject NavigationManager Navigation |
| 5 | + |
| 6 | + |
| 7 | +@if (AppConfiguration.Value.EnableTagDiscoveryPanel && IsOpen) |
| 8 | +{ |
| 9 | + <div class="position-fixed top-0 start-0 w-100 h-100 bg-dark bg-opacity-25" |
| 10 | + style="z-index:1040; backdrop-filter: blur(2px);" |
| 11 | + @onclick="Close"> |
| 12 | + </div> |
| 13 | + |
| 14 | + <div class="position-fixed top-0 start-0 w-100 h-100 d-flex justify-content-center align-items-center" |
| 15 | + style="z-index:1050; pointer-events:none;"> |
| 16 | + |
| 17 | + <div @ref="_panelRef" |
| 18 | + class="bg-body border rounded shadow p-3" |
| 19 | + style="max-width: 400px; max-height: 70vh; overflow-y:auto; pointer-events:auto;" |
| 20 | + tabindex="0" |
| 21 | + @onkeydown="HandleKeyDown"> |
| 22 | + |
| 23 | + @if (_tags.Count == 0) |
| 24 | + { |
| 25 | + <div class="text-muted text-center py-2"> |
| 26 | + No tags available yet. |
| 27 | + </div> |
| 28 | + } |
| 29 | + else |
| 30 | + { |
| 31 | + <div class="d-flex flex-wrap gap-2"> |
| 32 | + @foreach (var tag in _tags) |
| 33 | + { |
| 34 | + <span class="badge bg-secondary d-flex align-items-center gap-1" |
| 35 | + style="cursor: pointer;" |
| 36 | + @onclick="() => Navigate(tag.Name)"> |
| 37 | + @tag.Name |
| 38 | + <span class="badge bg-light text-dark">@tag.Count</span> |
| 39 | + </span> |
| 40 | + } |
| 41 | + </div> |
| 42 | + } |
| 43 | + </div> |
| 44 | + </div> |
| 45 | +} |
| 46 | + |
| 47 | +@code { |
| 48 | + [Parameter] public bool IsOpen { get; set; } |
| 49 | + [Parameter] public EventCallback OnClose { get; set; } |
| 50 | + |
| 51 | + private IReadOnlyList<TagCount> _tags = []; |
| 52 | + private ElementReference _panelRef; |
| 53 | + |
| 54 | + protected override async Task OnParametersSetAsync() |
| 55 | + { |
| 56 | + if (IsOpen) |
| 57 | + { |
| 58 | + _tags = await TagQueryService.GetAllOrderedByUsageAsync(); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + protected override async Task OnAfterRenderAsync(bool firstRender) |
| 63 | + { |
| 64 | + if (IsOpen) |
| 65 | + { |
| 66 | + await _panelRef.FocusAsync(); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + private async Task Close() |
| 71 | + { |
| 72 | + await OnClose.InvokeAsync(); |
| 73 | + } |
| 74 | + |
| 75 | + private async Task Navigate(string tag) |
| 76 | + { |
| 77 | + var encoded = Uri.EscapeDataString(tag); |
| 78 | + Navigation.NavigateTo($"/searchByTag/{encoded}"); |
| 79 | + await Close(); |
| 80 | + } |
| 81 | + |
| 82 | + private async Task HandleKeyDown(KeyboardEventArgs e) |
| 83 | + { |
| 84 | + if (e.Key == "Escape") |
| 85 | + { |
| 86 | + await Close(); |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments