Skip to content

Commit 249a71c

Browse files
committed
Refactor ResultsDisplay.razor for improved readability by adjusting indentation and formatting of conditional blocks and HTML elements.
1 parent 3baeae3 commit 249a71c

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

samples/Demo/Components/ResultsDisplay.razor

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
<h6><i class="fas fa-info-circle me-2"></i>Summary</h6>
2424
<p class="mb-0">@Response.Summary</p>
2525
</div>
26-
} @if (!string.IsNullOrEmpty(Response.GeneratedResponse))
26+
}
27+
@if (!string.IsNullOrEmpty(Response.GeneratedResponse))
2728
{
2829
<div class="alert alert-success">
2930
<h6><i class="fas fa-robot me-2"></i>Generated Answer</h6>
@@ -35,31 +36,37 @@
3536

3637
@if (Response.Results?.Any() == true)
3738
{
38-
<div class="results-container"> <div class="d-flex justify-content-between align-items-center mb-3">
39+
<div class="results-container">
40+
<div class="d-flex justify-content-between align-items-center mb-3">
3941
<h6 class="mb-0">Search Results</h6>
40-
<div class="btn-group btn-group-sm" role="group"> <input type="radio" class="btn-check" name="viewMode" id="cardView" checked="@(ViewMode == "card")" @onchange="SetCardView">
42+
<div class="btn-group btn-group-sm" role="group"> <input type="radio" class="btn-check" name="viewMode"
43+
id="cardView" checked="@(ViewMode == "card")" @onchange="SetCardView">
4144
<label class="btn btn-outline-secondary" for="cardView">
4245
<i class="fas fa-th-large"></i> Cards
4346
</label>
44-
<input type="radio" class="btn-check" name="viewMode" id="listView" checked="@(ViewMode == "list")" @onchange="SetListView">
47+
<input type="radio" class="btn-check" name="viewMode" id="listView" checked="@(ViewMode == "list")"
48+
@onchange="SetListView">
4549
<label class="btn btn-outline-secondary" for="listView">
4650
<i class="fas fa-list"></i> List
4751
</label>
4852
</div>
4953
</div>
5054

5155
@if (ViewMode == "card")
52-
{ <div class="row">
56+
{
57+
<div class="row">
5358
@foreach (var result in Response.Results.Take(DisplayLimit))
5459
{
5560
<div class="col-md-6 col-lg-4 mb-3">
56-
<div class="card h-100 result-card" style="cursor: pointer;" @onclick="() => HandleResultClick(result)">
61+
<div class="card h-100 result-card" style="cursor: pointer;"
62+
@onclick="() => HandleResultClick(result)">
5763
<div class="card-body">
5864
<div class="d-flex justify-content-between align-items-start mb-2">
5965
<h6 class="card-title">
6066
@if (!string.IsNullOrEmpty(result.Url))
6167
{
62-
<a href="@result.Url" target="_blank" class="text-decoration-none" @onclick:stopPropagation="true">
68+
<a href="@result.Url" target="_blank" class="text-decoration-none"
69+
@onclick:stopPropagation="true">
6370
@result.Name
6471
<i class="fas fa-external-link-alt fa-sm ms-1"></i>
6572
</a>
@@ -88,15 +95,18 @@
8895
</div>
8996
}
9097
else
91-
{ <div class="list-group">
98+
{
99+
100+
<div class="list-group">
92101
@foreach (var result in Response.Results.Take(DisplayLimit))
93102
{
94103
<div class="list-group-item" style="cursor: pointer;" @onclick="() => HandleResultClick(result)">
95104
<div class="d-flex w-100 justify-content-between align-items-center">
96105
<h6 class="mb-1">
97106
@if (!string.IsNullOrEmpty(result.Url))
98107
{
99-
<a href="@result.Url" target="_blank" class="text-decoration-none" @onclick:stopPropagation="true">
108+
<a href="@result.Url" target="_blank" class="text-decoration-none"
109+
@onclick:stopPropagation="true">
100110
@result.Name
101111
<i class="fas fa-external-link-alt fa-sm ms-1"></i>
102112
</a>
@@ -139,7 +149,8 @@
139149
<i class="fas fa-search fa-2x mb-3"></i>
140150
<p>No results found for your query.</p>
141151
</div>
142-
} @if (ShowDebugInfo && Response != null)
152+
}
153+
@if (ShowDebugInfo && Response != null)
143154
{
144155
<div class="mt-4 pt-3 border-top">
145156
<h6>
@@ -167,10 +178,12 @@
167178
.result-card {
168179
transition: transform 0.2s ease-in-out;
169180
}
181+
170182
.result-card:hover {
171183
transform: translateY(-2px);
172-
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
184+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
173185
}
186+
174187
.generated-answer {
175188
white-space: pre-wrap;
176189
line-height: 1.6;
@@ -181,9 +194,9 @@
181194
[Parameter] public NLWebResponse? Response { get; set; }
182195
[Parameter] public bool ShowDebugInfo { get; set; } = false;
183196
[Parameter] public EventCallback<NLWebResult> OnResultClicked { get; set; }
184-
197+
185198
private string ViewMode = "card";
186-
private int DisplayLimit = 6;private void ToggleDebugInfo()
199+
private int DisplayLimit = 6; private void ToggleDebugInfo()
187200
{
188201
ShowDebugInfo = !ShowDebugInfo;
189202
}
@@ -196,11 +209,12 @@
196209
private void SetCardView()
197210
{
198211
ViewMode = "card";
199-
} private void SetListView()
212+
}
213+
private void SetListView()
200214
{
201215
ViewMode = "list";
202216
}
203-
217+
204218
private async Task HandleResultClick(NLWebResult result)
205219
{
206220
if (OnResultClicked.HasDelegate)
@@ -213,26 +227,26 @@
213227
{
214228
if (string.IsNullOrEmpty(answer))
215229
return "";
216-
230+
217231
// Basic markdown-like formatting
218232
var formatted = answer
219-
.Replace("\n\n", "<br><br>")
220-
.Replace("\n", "<br>")
221-
.Replace("**", "<strong>")
222-
.Replace("**", "</strong>");
223-
233+
.Replace("\n\n", "<br><br>")
234+
.Replace("\n", "<br>")
235+
.Replace("**", "<strong>")
236+
.Replace("**", "</strong>");
237+
224238
return formatted;
225239
}
226240

227241
private string FormatJson(object? obj)
228242
{
229243
if (obj == null) return "null";
230-
244+
231245
try
232246
{
233-
return System.Text.Json.JsonSerializer.Serialize(obj, new System.Text.Json.JsonSerializerOptions
234-
{
235-
WriteIndented = true
247+
return System.Text.Json.JsonSerializer.Serialize(obj, new System.Text.Json.JsonSerializerOptions
248+
{
249+
WriteIndented = true
236250
});
237251
}
238252
catch

0 commit comments

Comments
 (0)