Skip to content

Commit 915841a

Browse files
committed
Added SearchPage
1 parent d5a28bd commit 915841a

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

LinkDotNet.Blog.Web/Pages/Admin/DraftBlogPosts.razor

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
@using LinkDotNet.Infrastructure.Persistence
33
@using LinkDotNet.Domain
44
@attribute [Authorize]
5-
@inject IRepository _repository
5+
@inject IRepository repository
66
<h3>Draft Blog Posts</h3>
77

88
<div class="content px-4">
9-
@for (var i = 0; i < _blogPosts.Count; i++)
9+
@for (var i = 0; i < blogPosts.Count; i++)
1010
{
11-
<ShortBlogPost BlogPost="_blogPosts[i]" UseAlternativeStyle="@(i % 2 != 0)"></ShortBlogPost>
11+
<ShortBlogPost BlogPost="blogPosts[i]" UseAlternativeStyle="@(i % 2 != 0)"></ShortBlogPost>
1212
}
1313
</div>
1414

1515
@code {
16-
private IList<BlogPost> _blogPosts = new List<BlogPost>();
16+
private IList<BlogPost> blogPosts = new List<BlogPost>();
1717

1818
protected override async Task OnInitializedAsync()
1919
{
20-
_blogPosts = (await _repository.GetAllAsync(p => !p.IsPublished, b => b.UpdatedDate)).ToList();
20+
blogPosts = (await repository.GetAllAsync(p => !p.IsPublished, b => b.UpdatedDate)).ToList();
2121
}
2222

2323
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page "/search/{searchTerm}"
2+
@using LinkDotNet.Infrastructure.Persistence
3+
@using LinkDotNet.Domain
4+
@inject IRepository repository
5+
<h3>Results for @SearchTerm</h3>
6+
7+
<div class="content px-4">
8+
@for (var i = 0; i < blogPosts.Count; i++)
9+
{
10+
<ShortBlogPost BlogPost="blogPosts[i]" UseAlternativeStyle="@(i % 2 != 0)"></ShortBlogPost>
11+
}
12+
</div>
13+
14+
@code {
15+
[Parameter]
16+
public string SearchTerm { get; set; }
17+
18+
private IList<BlogPost> blogPosts = new List<BlogPost>();
19+
20+
protected override async Task OnInitializedAsync()
21+
{
22+
blogPosts = (await repository.GetAllAsync(t => t.IsPublished && (t.Title.Contains(SearchTerm)
23+
|| t.Tags.Any(tag => tag.Content == SearchTerm)),
24+
b => b.UpdatedDate)).ToList();
25+
}
26+
}

0 commit comments

Comments
 (0)