diff --git a/src/PostIt/PostIt/App.axaml.cs b/src/PostIt/PostIt/App.axaml.cs index 1a68f4ac..2065bd53 100644 --- a/src/PostIt/PostIt/App.axaml.cs +++ b/src/PostIt/PostIt/App.axaml.cs @@ -183,6 +183,7 @@ public partial class App : Application // here — the parametrised ctors stay for direct test wiring. services.AddTransient(); services.AddTransient(); + // ViewModels services.AddSingleton(settings); services.AddSingleton(api); diff --git a/src/PostIt/PostIt/ViewModels/CirclesPageViewModel.cs b/src/PostIt/PostIt/ViewModels/CirclesPageViewModel.cs index bfc431b8..c017c426 100644 --- a/src/PostIt/PostIt/ViewModels/CirclesPageViewModel.cs +++ b/src/PostIt/PostIt/ViewModels/CirclesPageViewModel.cs @@ -1,10 +1,9 @@ using System; using System.Collections.ObjectModel; +using System.Linq; using System.Threading.Tasks; -using Avalonia; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; -using Microsoft.Extensions.DependencyInjection; using PostIt.Services; using Yavsc.Api.Client; using Yavsc.Api.Client.Dtos; @@ -64,6 +63,12 @@ public partial class CirclesPageViewModel : ViewModelBase [ObservableProperty] public partial string StatusMessage { get; set; } = string.Empty; + /// + /// Raised when the user wants to add a member to the + /// currently selected circle. The view listens to this + /// event and opens AddCircleMemberDialog. + /// + public event EventHandler? AddMemberRequested; public CirclesPageViewModel(CircleApiClient client) { @@ -111,16 +116,6 @@ public partial class CirclesPageViewModel : ViewModelBase } } - [RelayCommand] - internal async Task OpenAddMemberAsync() - { - var app = Application.Current as App; - var services = app?.ServiceProvider; - var directory = services.GetRequiredService(); - AddCircleMemberDialogViewModel model = - new AddCircleMemberDialogViewModel(directory); - await app.PushPageAsync(model); - } /// /// Load the members of one of the caller's circles. The /// server scopes the endpoint with a 404 when the circle @@ -236,6 +231,22 @@ public partial class CirclesPageViewModel : ViewModelBase } } + /// + /// Fire the event so + /// the view opens AddCircleMemberDialog. The view + /// forwards the dialog's Confirmed event back to + /// . + /// + [RelayCommand] + public void OpenAddMember() + { + if (SelectedCircle is null) + { + StatusMessage = "Sélectionnez d'abord un cercle"; + return; + } + AddMemberRequested?.Invoke(this, EventArgs.Empty); + } /// /// Called by the view when the dialog confirms a diff --git a/src/PostIt/PostIt/Views/AddCircleMemberDialog.axaml b/src/PostIt/PostIt/Views/AddCircleMemberDialog.axaml index 5d1e2531..2c13e99c 100644 --- a/src/PostIt/PostIt/Views/AddCircleMemberDialog.axaml +++ b/src/PostIt/PostIt/Views/AddCircleMemberDialog.axaml @@ -16,7 +16,7 @@ PlaceholderText="Nom ou email d'un utilisateur Yavsc..." HorizontalAlignment="Stretch"/> [Produces("application/json")] - [Route( Constants.APIPrefix + "/user-search")] + [Route("api/user-search")] [Authorize] public class UserSearchApiController : Controller { @@ -108,4 +108,4 @@ namespace Yavsc.Blogs.Controllers public string? Avatar { get; set; } public string? Email { get; set; } } -} +} \ No newline at end of file