|
23 | 23 | <h6><i class="fas fa-info-circle me-2"></i>Summary</h6> |
24 | 24 | <p class="mb-0">@Response.Summary</p> |
25 | 25 | </div> |
26 | | - } @if (!string.IsNullOrEmpty(Response.GeneratedResponse)) |
| 26 | + } |
| 27 | + @if (!string.IsNullOrEmpty(Response.GeneratedResponse)) |
27 | 28 | { |
28 | 29 | <div class="alert alert-success"> |
29 | 30 | <h6><i class="fas fa-robot me-2"></i>Generated Answer</h6> |
|
35 | 36 |
|
36 | 37 | @if (Response.Results?.Any() == true) |
37 | 38 | { |
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"> |
39 | 41 | <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"> |
41 | 44 | <label class="btn btn-outline-secondary" for="cardView"> |
42 | 45 | <i class="fas fa-th-large"></i> Cards |
43 | 46 | </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"> |
45 | 49 | <label class="btn btn-outline-secondary" for="listView"> |
46 | 50 | <i class="fas fa-list"></i> List |
47 | 51 | </label> |
48 | 52 | </div> |
49 | 53 | </div> |
50 | 54 |
|
51 | 55 | @if (ViewMode == "card") |
52 | | - { <div class="row"> |
| 56 | + { |
| 57 | + <div class="row"> |
53 | 58 | @foreach (var result in Response.Results.Take(DisplayLimit)) |
54 | 59 | { |
55 | 60 | <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)"> |
57 | 63 | <div class="card-body"> |
58 | 64 | <div class="d-flex justify-content-between align-items-start mb-2"> |
59 | 65 | <h6 class="card-title"> |
60 | 66 | @if (!string.IsNullOrEmpty(result.Url)) |
61 | 67 | { |
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"> |
63 | 70 | @result.Name |
64 | 71 | <i class="fas fa-external-link-alt fa-sm ms-1"></i> |
65 | 72 | </a> |
|
88 | 95 | </div> |
89 | 96 | } |
90 | 97 | else |
91 | | - { <div class="list-group"> |
| 98 | + { |
| 99 | + |
| 100 | + <div class="list-group"> |
92 | 101 | @foreach (var result in Response.Results.Take(DisplayLimit)) |
93 | 102 | { |
94 | 103 | <div class="list-group-item" style="cursor: pointer;" @onclick="() => HandleResultClick(result)"> |
95 | 104 | <div class="d-flex w-100 justify-content-between align-items-center"> |
96 | 105 | <h6 class="mb-1"> |
97 | 106 | @if (!string.IsNullOrEmpty(result.Url)) |
98 | 107 | { |
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"> |
100 | 110 | @result.Name |
101 | 111 | <i class="fas fa-external-link-alt fa-sm ms-1"></i> |
102 | 112 | </a> |
|
139 | 149 | <i class="fas fa-search fa-2x mb-3"></i> |
140 | 150 | <p>No results found for your query.</p> |
141 | 151 | </div> |
142 | | - } @if (ShowDebugInfo && Response != null) |
| 152 | + } |
| 153 | + @if (ShowDebugInfo && Response != null) |
143 | 154 | { |
144 | 155 | <div class="mt-4 pt-3 border-top"> |
145 | 156 | <h6> |
|
167 | 178 | .result-card { |
168 | 179 | transition: transform 0.2s ease-in-out; |
169 | 180 | } |
| 181 | +
|
170 | 182 | .result-card:hover { |
171 | 183 | 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); |
173 | 185 | } |
| 186 | +
|
174 | 187 | .generated-answer { |
175 | 188 | white-space: pre-wrap; |
176 | 189 | line-height: 1.6; |
|
181 | 194 | [Parameter] public NLWebResponse? Response { get; set; } |
182 | 195 | [Parameter] public bool ShowDebugInfo { get; set; } = false; |
183 | 196 | [Parameter] public EventCallback<NLWebResult> OnResultClicked { get; set; } |
184 | | - |
| 197 | + |
185 | 198 | private string ViewMode = "card"; |
186 | | - private int DisplayLimit = 6;private void ToggleDebugInfo() |
| 199 | + private int DisplayLimit = 6; private void ToggleDebugInfo() |
187 | 200 | { |
188 | 201 | ShowDebugInfo = !ShowDebugInfo; |
189 | 202 | } |
|
196 | 209 | private void SetCardView() |
197 | 210 | { |
198 | 211 | ViewMode = "card"; |
199 | | - } private void SetListView() |
| 212 | + } |
| 213 | + private void SetListView() |
200 | 214 | { |
201 | 215 | ViewMode = "list"; |
202 | 216 | } |
203 | | - |
| 217 | + |
204 | 218 | private async Task HandleResultClick(NLWebResult result) |
205 | 219 | { |
206 | 220 | if (OnResultClicked.HasDelegate) |
|
213 | 227 | { |
214 | 228 | if (string.IsNullOrEmpty(answer)) |
215 | 229 | return ""; |
216 | | - |
| 230 | + |
217 | 231 | // Basic markdown-like formatting |
218 | 232 | 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 | + |
224 | 238 | return formatted; |
225 | 239 | } |
226 | 240 |
|
227 | 241 | private string FormatJson(object? obj) |
228 | 242 | { |
229 | 243 | if (obj == null) return "null"; |
230 | | - |
| 244 | + |
231 | 245 | try |
232 | 246 | { |
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 |
236 | 250 | }); |
237 | 251 | } |
238 | 252 | catch |
|
0 commit comments