Skip to content

Commit 3db5cf2

Browse files
Use InputSelect component with @bind-Value:after for reliable change detection
Co-authored-by: StuartFerguson <[email protected]>
1 parent 85c444e commit 3db5cf2

1 file changed

Lines changed: 8 additions & 17 deletions

File tree

  • EstateManagementUI.BlazorServer/Components/Pages

EstateManagementUI.BlazorServer/Components/Pages/Home.razor

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@page "/"
22
@using MediatR
33
@using Microsoft.AspNetCore.Components.Authorization
4+
@using Microsoft.AspNetCore.Components.Forms
45
@using EstateManagementUI.BlazorServer.Permissions
56
@using EstateManagementUI.BlazorServer.Requests
67
@using EstateManagementUI.BlazorServer.Models
@@ -108,15 +109,15 @@
108109
<!-- Comparison Date Selection (moved here) -->
109110
<div class="flex items-center gap-4 bg-white p-4 rounded-lg shadow-admin">
110111
<label class="text-sm font-medium text-gray-700">Compare to:</label>
111-
<select value="@SelectedComparisonDate" @onchange="HandleDateSelectionChanged" class="form-control max-w-xs">
112+
<InputSelect @bind-Value="_selectedComparisonDate" @bind-Value:after="OnComparisonDateChanged" class="form-control max-w-xs">
112113
@if (comparisonDates != null)
113114
{
114115
@foreach (var date in comparisonDates)
115116
{
116117
<option value="@date.Date.ToString("yyyy-MM-dd")">@date.Description</option>
117118
}
118119
}
119-
</select>
120+
</InputSelect>
120121
</div>
121122

122123
<!-- Comparison Cards Row 2 - Sales Data -->
@@ -220,13 +221,6 @@
220221
private List<MerchantModel>? recentMerchants;
221222
private string _selectedComparisonDate = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd");
222223

223-
224-
private string SelectedComparisonDate
225-
{
226-
get => _selectedComparisonDate;
227-
set => _selectedComparisonDate = value;
228-
}
229-
230224
protected override async Task OnInitializedAsync()
231225
{
232226
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
@@ -324,16 +318,13 @@
324318
StateHasChanged();
325319
}
326320
}
327-
private async Task HandleDateSelectionChanged(ChangeEventArgs e)
321+
private async Task OnComparisonDateChanged()
328322
{
329-
if (e.Value != null)
323+
// This is called after _selectedComparisonDate is updated by @bind-Value
324+
if (!isAdministrator)
330325
{
331-
_selectedComparisonDate = e.Value.ToString()!;
332-
if (!isAdministrator)
333-
{
334-
await LoadDashboardData();
335-
StateHasChanged();
336-
}
326+
await LoadDashboardData();
327+
StateHasChanged();
337328
}
338329
}
339330

0 commit comments

Comments
 (0)