Skip to content

Commit 1b1190f

Browse files
committed
fix: addressing review feedback; fixing tests and improve TagDiscoveryPanel behaviour
1 parent b4dc0a1 commit 1b1190f

5 files changed

Lines changed: 81 additions & 91 deletions

File tree

src/LinkDotNet.Blog.Web/Features/Home/Components/NavMenu.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
<a class="nav-link d-flex align-items-center justify-content-center" @onclick="ToggleTagDiscoveryPanel"
6666
style="font-family: 'icons'; font-weight: 900; cursor: pointer;"
6767
title="Discover new topics"> &#xE936; </a>
68-
<TagDiscoveryPanel IsOpen="@_isOpen" OnClose="CloseTagDiscoveryPanel" />
6968
</li>
7069
}
7170

@@ -76,6 +75,7 @@
7675
</div>
7776
</div>
7877
</nav>
78+
<TagDiscoveryPanel IsOpen="@_isOpen" OnClose="CloseTagDiscoveryPanel" />
7979

8080
@code {
8181
private string currentUri = string.Empty;
Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,55 @@
1+
@using Microsoft.AspNetCore.Components.Web;
12
@inject ITagQueryService TagQueryService
23
@inject IOptions<ApplicationConfiguration> AppConfiguration
34
@inject NavigationManager Navigation
45

5-
@if (!AppConfiguration.Value.EnableTagDiscoveryPanel || !IsOpen) { return; }
66

7-
<div class="position-fixed top-0 start-0 w-100 h-100 bg-dark bg-opacity-25"
8-
style="z-index:1040; backdrop-filter: blur(2px);"
9-
@onclick="Close">
10-
</div>
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>
1113

12-
<div class="position-fixed top-50 start-50 translate-middle bg-body border rounded shadow p-3"
13-
style="max-width: 400px; max-height: 70vh; overflow-y:auto; z-index:1050;">
14-
<div class="d-flex flex-wrap gap-2">
15-
@foreach (var tag in _tags)
16-
{
17-
<span class="badge bg-secondary d-flex align-items-center gap-1"
18-
style="cursor: pointer;"
19-
@onclick="() => Navigate(tag.Name)">
20-
@tag.Name
21-
<span class="badge bg-light text-dark">@tag.Count</span>
22-
</span>
23-
}
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>
2444
</div>
25-
</div>
45+
}
2646

2747
@code {
2848
[Parameter] public bool IsOpen { get; set; }
2949
[Parameter] public EventCallback OnClose { get; set; }
3050

3151
private IReadOnlyList<TagCount> _tags = [];
52+
private ElementReference _panelRef;
3253

3354
protected override async Task OnParametersSetAsync()
3455
{
@@ -38,6 +59,14 @@
3859
}
3960
}
4061

62+
protected override async Task OnAfterRenderAsync(bool firstRender)
63+
{
64+
if (IsOpen)
65+
{
66+
await _panelRef.FocusAsync();
67+
}
68+
}
69+
4170
private async Task Close()
4271
{
4372
await OnClose.InvokeAsync();
@@ -49,4 +78,12 @@
4978
Navigation.NavigateTo($"/searchByTag/{encoded}");
5079
await Close();
5180
}
81+
82+
private async Task HandleKeyDown(KeyboardEventArgs e)
83+
{
84+
if (e.Key == "Escape")
85+
{
86+
await Close();
87+
}
88+
}
5289
}

src/LinkDotNet.Blog.Web/Features/TagDiscovery/TagDiscoveryPanel.razor.css

Lines changed: 0 additions & 70 deletions
This file was deleted.

tests/LinkDotNet.Blog.IntegrationTests/Web/Shared/NavMenuTests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
using System.Linq;
21
using AngleSharp.Html.Dom;
32
using LinkDotNet.Blog.TestUtilities;
43
using LinkDotNet.Blog.Web.Features.Home.Components;
54
using LinkDotNet.Blog.Web.Features.Services;
5+
using LinkDotNet.Blog.Web.Features.Services.Tags;
66
using Microsoft.AspNetCore.Components;
77
using Microsoft.Extensions.DependencyInjection;
88
using Microsoft.Extensions.Options;
9+
using System.Linq;
910

1011
namespace LinkDotNet.Blog.IntegrationTests.Web.Shared;
1112

@@ -14,6 +15,13 @@ public class NavMenuTests : BunitContext
1415
public NavMenuTests()
1516
{
1617
ComponentFactories.Add<ThemeToggler, ThemeTogglerStub>();
18+
19+
var tagQueryService = Substitute.For<ITagQueryService>();
20+
Services.AddSingleton(tagQueryService);
21+
22+
Services.AddSingleton(
23+
Options.Create(new ApplicationConfigurationBuilder().Build())
24+
);
1725
}
1826

1927
[Fact]

tests/LinkDotNet.Blog.UnitTests/Web/Features/Services/Tags/TagQueryServiceTests.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,40 @@
22
using LinkDotNet.Blog.Infrastructure;
33
using LinkDotNet.Blog.Infrastructure.Persistence;
44
using LinkDotNet.Blog.TestUtilities;
5+
using LinkDotNet.Blog.Web;
56
using LinkDotNet.Blog.Web.Features.Services.Tags;
7+
using Microsoft.Extensions.Caching.Memory;
8+
using Microsoft.Extensions.Options;
69
using MongoDB.Driver;
710
using NSubstitute;
811
using System;
912
using System.Collections.Generic;
1013
using System.Text;
1114
using System.Threading.Tasks;
15+
using ZiggyCreatures.Caching.Fusion;
16+
1217

1318
namespace LinkDotNet.Blog.UnitTests.Web.Features.Services.Tags;
1419
public sealed class TagQueryServiceTests
1520
{
1621

1722
private readonly IRepository<BlogPost> repository;
1823
private readonly TagQueryService tagQueryService;
24+
private readonly IFusionCache fusionCache;
1925

2026
public TagQueryServiceTests()
2127
{
2228
repository = Substitute.For<IRepository<BlogPost>>();
23-
tagQueryService = new TagQueryService(repository);
29+
30+
fusionCache = new FusionCache(
31+
new FusionCacheOptions(),
32+
logger: null,
33+
memoryCache: new MemoryCache(new MemoryCacheOptions())
34+
);
35+
36+
var config = Options.Create(new ApplicationConfigurationBuilder().Build());
37+
38+
tagQueryService = new TagQueryService(repository, fusionCache, config);
2439
}
2540

2641
[Fact]

0 commit comments

Comments
 (0)