Skip to content

Commit 544b0ea

Browse files
CopilotKeboo
andauthored
Fix UserDialog role selection applying changes before OK (#454)
* Initial plan * Implement temporary fields and commit pattern for UserDialog Co-authored-by: Keboo <[email protected]> * Simplifies user dialog state management Removes temporary properties and explicit commit/initialization methods from the user dialog view model. This allows for direct binding to view model properties, streamlining data flow and reducing boilerplate. Introduces a loading indicator within the user dialog to provide better user feedback during data fetching. Updates server launch profiles to use `pointerstar.dev.localhost` for HTTPS and removes unnecessary configurations. Also removes an unused partial class declaration from `Program.cs`. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Keboo <[email protected]> Co-authored-by: Kevin Bost <[email protected]>
1 parent c000a6b commit 544b0ea

File tree

5 files changed

+79
-59
lines changed

5 files changed

+79
-59
lines changed

PointerStar/Client/Components/UserDialog.razor

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,33 @@
1111
<MudButtonGroup OverrideStyles="false">
1212
<MudButton Color="Color.Primary"
1313
Variant="@(ViewModel.SelectedRoleId == Role.TeamMember.Id ? Variant.Filled : Variant.Outlined)"
14-
OnClick="() => ViewModel.SelectRole(Role.TeamMember)">
14+
OnClick="() => ViewModel.SelectRole(Role.TeamMember)"
15+
Disabled="ViewModel.IsLoading">
1516
Vote
1617
</MudButton>
1718
<MudButton Color="Color.Primary"
1819
Variant="@(ViewModel.SelectedRoleId == Role.Facilitator.Id ? Variant.Filled : Variant.Outlined)"
19-
OnClick="() => ViewModel.SelectRole(Role.Facilitator)">
20+
OnClick="() => ViewModel.SelectRole(Role.Facilitator)"
21+
Disabled="ViewModel.IsLoading">
2022
Facilitate
2123
</MudButton>
2224
<MudButton Color="Color.Primary"
2325
Variant="@(ViewModel.SelectedRoleId == Role.Observer.Id ? Variant.Filled : Variant.Outlined)"
24-
OnClick="() => ViewModel.SelectRole(Role.Observer)">
26+
OnClick="() => ViewModel.SelectRole(Role.Observer)"
27+
Disabled="ViewModel.IsLoading">
2528
Observe
2629
</MudButton>
2730
</MudButtonGroup>
31+
@if (ViewModel.IsLoading)
32+
{
33+
<MudProgressCircular Size="Size.Small" Indeterminate="true" />
34+
}
2835
</MudStack>
2936
</MudStack>
3037
</DialogContent>
3138
<DialogActions>
32-
<MudButton OnClick="Cancel">Cancel</MudButton>
33-
<MudButton Color="Color.Primary" OnClick="Submit">Ok</MudButton>
39+
<MudButton OnClick="Cancel" Disabled="ViewModel.IsLoading">Cancel</MudButton>
40+
<MudButton Color="Color.Primary" OnClick="Submit" Disabled="ViewModel.IsLoading">Ok</MudButton>
3441
</DialogActions>
3542
</MudDialog>
3643

@@ -44,7 +51,11 @@
4451
[Parameter]
4552
public Guid? SelectedRoleId { get; set; }
4653

47-
private void Submit() => MudDialog?.Close(DialogResult.Ok(ViewModel));
54+
private void Submit()
55+
{
56+
MudDialog?.Close(DialogResult.Ok(ViewModel));
57+
}
58+
4859
private void Cancel() => MudDialog?.Cancel();
4960

5061
protected override async Task OnParametersSetAsync()

PointerStar/Client/ViewModels/UserDialogViewModel.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public partial class UserDialogViewModel : ViewModelBase
1010
[ObservableProperty]
1111
private Guid? _selectedRoleId;
1212

13+
[ObservableProperty]
14+
private bool _isLoading;
15+
1316
private HttpClient HttpClient { get; }
1417
private IRoomHubConnection RoomHubConnection { get; }
1518

@@ -27,10 +30,20 @@ public void SelectRole(Role? role)
2730
public async Task LoadRoomDataAsync(string? roomId)
2831
{
2932
if (SelectedRoleId is null &&
30-
roomId is not null &&
31-
await HttpClient.GetFromJsonAsync<Role>($"/api/room/GetNewUserRole/{roomId}") is { } newUserRole)
33+
roomId is not null)
3234
{
33-
SelectedRoleId = newUserRole.Id;
35+
IsLoading = true;
36+
try
37+
{
38+
if (await HttpClient.GetFromJsonAsync<Role>($"/api/room/GetNewUserRole/{roomId}") is { } newUserRole)
39+
{
40+
SelectedRoleId = newUserRole.Id;
41+
}
42+
}
43+
finally
44+
{
45+
IsLoading = false;
46+
}
3447
}
3548
}
3649
}

PointerStar/Server/Program.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,3 @@
6161

6262
app.Run();
6363

64-
65-
//Just doing this to make the generated class public
66-
public partial class Program { }
Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,34 @@
11
{
2-
"iisSettings": {
3-
"windowsAuthentication": false,
4-
"anonymousAuthentication": true,
5-
"iisExpress": {
6-
"applicationUrl": "http://localhost:13580",
7-
"sslPort": 44352
8-
}
2+
"profiles": {
3+
"https": {
4+
"commandName": "Project",
5+
"dotnetRunMessages": true,
6+
"launchBrowser": true,
7+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
8+
"applicationUrl": "https://pointerstar.dev.localhost:7017;http://pointerstar.dev.localhost:5290",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development"
11+
}
912
},
10-
"profiles": {
11-
"http": {
12-
"commandName": "Project",
13-
"dotnetRunMessages": true,
14-
"launchBrowser": true,
15-
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
16-
"applicationUrl": "http://localhost:5225",
17-
"environmentVariables": {
18-
"ASPNETCORE_ENVIRONMENT": "Development"
19-
}
20-
},
21-
"https": {
22-
"commandName": "Project",
23-
"dotnetRunMessages": true,
24-
"launchBrowser": true,
25-
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
26-
"applicationUrl": "https://localhost:7234;http://localhost:5225",
27-
"environmentVariables": {
28-
"ASPNETCORE_ENVIRONMENT": "Development"
29-
}
30-
},
31-
"test-room": {
32-
"commandName": "Project",
33-
"dotnetRunMessages": true,
34-
"launchBrowser": true,
35-
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
36-
"applicationUrl": "https://localhost:7234;http://localhost:5225",
37-
"launchUrl": "https://localhost:7234/room/testing-room",
38-
"environmentVariables": {
39-
"ASPNETCORE_ENVIRONMENT": "Development"
40-
}
41-
},
42-
"IIS Express": {
43-
"commandName": "IISExpress",
44-
"launchBrowser": true,
45-
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
46-
"environmentVariables": {
47-
"ASPNETCORE_ENVIRONMENT": "Development"
48-
}
49-
}
13+
"test-room": {
14+
"commandName": "Project",
15+
"dotnetRunMessages": true,
16+
"launchBrowser": true,
17+
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
18+
"applicationUrl": "https://localhost:7234;http://localhost:5225",
19+
"launchUrl": "https://localhost:7234/room/testing-room",
20+
"environmentVariables": {
21+
"ASPNETCORE_ENVIRONMENT": "Development"
22+
}
23+
},
24+
"https-no-debug": {
25+
"commandName": "Project",
26+
"dotnetRunMessages": true,
27+
"launchBrowser": true,
28+
"applicationUrl": "https://pointerstar.dev.localhost:7017;http://pointerstar.dev.localhost:5290",
29+
"environmentVariables": {
30+
"ASPNETCORE_ENVIRONMENT": "Development"
31+
}
5032
}
33+
}
5134
}

Tests/PointerStar.Client.Tests/ViewModels/UserDialogViewModelTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,20 @@ public async Task LoadRoomDataAsync_WithoutRoomIdAndRoleSet_DoesNothing()
7070

7171
Assert.Equal(Role.Facilitator.Id, viewModel.SelectedRoleId);
7272
}
73+
74+
[Fact]
75+
public async Task LoadRoomDataAsync_ResetsIsLoadingAfterOperation()
76+
{
77+
AutoMocker mocker = new();
78+
mocker.SetupHttpGet(new Uri("/api/room/GetNewUserRole/1", UriKind.Relative))
79+
.ReturnsJson(Role.TeamMember);
80+
81+
UserDialogViewModel viewModel = mocker.CreateInstance<UserDialogViewModel>();
82+
83+
Assert.False(viewModel.IsLoading);
84+
85+
await viewModel.LoadRoomDataAsync("1");
86+
87+
Assert.False(viewModel.IsLoading);
88+
}
7389
}

0 commit comments

Comments
 (0)