Skip to content

Commit 3baeae3

Browse files
committed
Demo app fixes.
Enhance ResultsDisplay component with clickable result cards and list items, and implement OnResultClicked event callback
1 parent 2fcc224 commit 3baeae3

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

samples/Demo/Components/ResultsDisplay.razor

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,17 @@
4949
</div>
5050

5151
@if (ViewMode == "card")
52-
{
53-
<div class="row">
52+
{ <div class="row">
5453
@foreach (var result in Response.Results.Take(DisplayLimit))
5554
{
5655
<div class="col-md-6 col-lg-4 mb-3">
57-
<div class="card h-100 result-card">
56+
<div class="card h-100 result-card" style="cursor: pointer;" @onclick="() => HandleResultClick(result)">
5857
<div class="card-body">
5958
<div class="d-flex justify-content-between align-items-start mb-2">
6059
<h6 class="card-title">
6160
@if (!string.IsNullOrEmpty(result.Url))
6261
{
63-
<a href="@result.Url" target="_blank" class="text-decoration-none">
62+
<a href="@result.Url" target="_blank" class="text-decoration-none" @onclick:stopPropagation="true">
6463
@result.Name
6564
<i class="fas fa-external-link-alt fa-sm ms-1"></i>
6665
</a>
@@ -89,16 +88,15 @@
8988
</div>
9089
}
9190
else
92-
{
93-
<div class="list-group">
91+
{ <div class="list-group">
9492
@foreach (var result in Response.Results.Take(DisplayLimit))
9593
{
96-
<div class="list-group-item">
94+
<div class="list-group-item" style="cursor: pointer;" @onclick="() => HandleResultClick(result)">
9795
<div class="d-flex w-100 justify-content-between align-items-center">
9896
<h6 class="mb-1">
9997
@if (!string.IsNullOrEmpty(result.Url))
10098
{
101-
<a href="@result.Url" target="_blank" class="text-decoration-none">
99+
<a href="@result.Url" target="_blank" class="text-decoration-none" @onclick:stopPropagation="true">
102100
@result.Name
103101
<i class="fas fa-external-link-alt fa-sm ms-1"></i>
104102
</a>
@@ -182,9 +180,10 @@
182180
@code {
183181
[Parameter] public NLWebResponse? Response { get; set; }
184182
[Parameter] public bool ShowDebugInfo { get; set; } = false;
183+
[Parameter] public EventCallback<NLWebResult> OnResultClicked { get; set; }
185184

186185
private string ViewMode = "card";
187-
private int DisplayLimit = 6; private void ToggleDebugInfo()
186+
private int DisplayLimit = 6;private void ToggleDebugInfo()
188187
{
189188
ShowDebugInfo = !ShowDebugInfo;
190189
}
@@ -197,12 +196,18 @@
197196
private void SetCardView()
198197
{
199198
ViewMode = "card";
200-
}
201-
202-
private void SetListView()
199+
} private void SetListView()
203200
{
204201
ViewMode = "list";
205202
}
203+
204+
private async Task HandleResultClick(NLWebResult result)
205+
{
206+
if (OnResultClicked.HasDelegate)
207+
{
208+
await OnResultClicked.InvokeAsync(result);
209+
}
210+
}
206211

207212
private string FormatGeneratedAnswer(string answer)
208213
{

samples/Demo/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
builder.Services.AddRazorComponents()
1414
.AddInteractiveServerComponents();
1515

16+
// Add HttpClient for Blazor components
17+
builder.Services.AddHttpClient();
18+
1619
// Add CORS configuration
1720
builder.Services.AddCors(options =>
1821
{

0 commit comments

Comments
 (0)