Skip to content

Commit 1ec455a

Browse files
author
Ajay kumar
committed
[Blog] [Ajay]: Implement search blog feature
1 parent 28727e3 commit 1ec455a

File tree

5 files changed

+71
-6
lines changed

5 files changed

+71
-6
lines changed

TestArena/Blog/Common/BlogImage.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@using System.ComponentModel.DataAnnotations
22

33
@code {
4-
[Required] [Parameter] public string ImagePath { get; set; }
5-
[Required] [Parameter] public string Description { get; set; }
4+
[Required] [Parameter] public string ImagePath { get; set; } = "#";
5+
[Required] [Parameter] public string Description { get; set; } = "NA";
66
[Parameter] public int Number { get; set; }
77

88
private bool IsMagnified { get; set; } = false;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Collections.Generic;
2+
3+
namespace TestArena.Blog.Common.NavigationUtils
4+
{
5+
public static class SiteMap
6+
{
7+
public static List<PageInfo> Pages { get; } = new List<PageInfo>
8+
{
9+
new("Intro to PACT for .NET Core: API contract testing", "/blog/contract-testing-pact-net-intro"),
10+
new("Intro to PACT for .NET Core: Events based systems", "/blog/contract-testing-in-pact-with-events"),
11+
new("Intro to PACT for .NET Core: Integration with PactFlow", "/blog/integration-with-pactflow")
12+
};
13+
}
14+
15+
public class PageInfo
16+
{
17+
public string Header { get; }
18+
public string RelativePath { get; }
19+
20+
public PageInfo(string header, string relativePath)
21+
{
22+
Header = header;
23+
RelativePath = relativePath;
24+
}
25+
}
26+
}

TestArena/Blog/PactNet/handling-events/Index.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@using TestArena.Blog.Common
33

44
<BlogContainer>
5-
<Header Title="Intro to PACT for .NET Core: API contract testing"
5+
<Header Title="Intro to PACT for .NET Core: Events based systems"
66
Image="images/blog/pact/events-demo/contract-testing-events.webp" PublishedOn="@DateTime.Now" Authors="Ajay Kumar">
77
</Header>
88

TestArena/Layout/HeaderComponent.razor

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
</div>
1414

1515
<!-- Search bar in the center -->
16-
<div class="col-12 col-md-4 d-flex justify-content-md-center justify-content-center mt-2 mt-md-0">
17-
<input type="text" class="form-control w-75" placeholder="Search...">
18-
</div>
16+
<HeaderSearchBar />
1917

2018
<!-- Settings button on the right -->
2119
<div class="col-12 col-md-4 d-flex justify-content-md-end justify-content-center mt-2 mt-md-0">
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@using TestArena.Layout
2+
@using TestArena.Blog.Common.NavigationUtils
3+
4+
<div class="col-12 col-md-4 d-flex justify-content-md-center justify-content-center mt-2 mt-md-0">
5+
<div class="w-75 position-relative">
6+
<input type="text" class="form-control" placeholder="Search..." @oninput="FilterPages">
7+
<ul class="list-group position-absolute w-100 mt-1" style="z-index: 1000;" hidden="@(!FilteredPages.Any())">
8+
@foreach (var filteredPage in FilteredPages)
9+
{
10+
<li class="list-group-item p-0">
11+
<a href="@filteredPage.RelativePath" class="d-block text-decoration-none p-2" @onclick="() => HideDropdown()">@filteredPage.Header</a>
12+
</li>
13+
}
14+
</ul>
15+
</div>
16+
</div>
17+
18+
@code {
19+
private string SearchText { get; set; } = string.Empty;
20+
private List<PageInfo> FilteredPages { get; set; } = new();
21+
22+
private void FilterPages(ChangeEventArgs e)
23+
{
24+
SearchText = e.Value?.ToString() ?? string.Empty;
25+
if (string.IsNullOrWhiteSpace(SearchText))
26+
{
27+
FilteredPages.Clear();
28+
}
29+
else
30+
{
31+
FilteredPages = SiteMap.Pages
32+
.Where(page => page.Header.Contains(SearchText, StringComparison.OrdinalIgnoreCase))
33+
.ToList();
34+
}
35+
}
36+
37+
private void HideDropdown()
38+
{
39+
FilteredPages.Clear();
40+
}
41+
}

0 commit comments

Comments
 (0)