diff --git a/src/PostIt/PostIt/App.axaml.cs b/src/PostIt/PostIt/App.axaml.cs index 2065bd53..1a68f4ac 100644 --- a/src/PostIt/PostIt/App.axaml.cs +++ b/src/PostIt/PostIt/App.axaml.cs @@ -183,7 +183,6 @@ 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 c017c426..bfc431b8 100644 --- a/src/PostIt/PostIt/ViewModels/CirclesPageViewModel.cs +++ b/src/PostIt/PostIt/ViewModels/CirclesPageViewModel.cs @@ -1,9 +1,10 @@ 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; @@ -63,12 +64,6 @@ 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) { @@ -116,6 +111,16 @@ 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 @@ -231,22 +236,6 @@ 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 2c13e99c..5d1e2531 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("api/user-search")] + [Route( Constants.APIPrefix + "/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 +}