ADD : navigation when clicked button details page book & Toast message

commands-19-09
Lou BRODA 1 year ago
parent 844f9b97fb
commit ed0f18ae25

@ -71,7 +71,7 @@
</Grid>
<CollectionView ItemsSource="{Binding ContactsVM.Manager.AllContacts}"
SelectedItem="{Binding ContactsVM.Manager.SelectedContact}"
SelectionChangedCommand="{Binding ContactsVM.Manager.LendBookCommand}"
SelectionChangedCommand="{Binding ContactsVM.BookLendedCommand}"
SelectionChangedCommandParameter="{Binding ContactsVM.Manager.SelectedContact}"
SelectionMode="Single"
Grid.Row="4">

@ -310,7 +310,7 @@
<contentView:DetailsLivreButtonView ButtonIcon="heart.png"
ButtonTitle="Ajouter aux favoris"
ButtonCommand="{Binding DetailsLivreVM.Manager.AddToFavoritesCommand}"
ButtonCommand="{Binding DetailsLivreVM.AddBookToFavoritesCommand}"
ButtonCommandParameter="{Binding DetailsLivreVM.Book}"/>
<contentView:SeparatorCutStartView/>
@ -322,7 +322,7 @@
<contentView:DetailsLivreButtonView ButtonIcon="rounded_plus.png"
ButtonTitle="Ajouter à la liste À lire plus tard"
ButtonCommand="{Binding DetailsLivreVM.Manager.UpdateToBeReadBookCommand}"
ButtonCommand="{Binding DetailsLivreVM.AddBookToReadListCommand}"
ButtonCommandParameter="{Binding DetailsLivreVM.Book}"/>
<contentView:SeparatorCutStartView/>
@ -341,7 +341,7 @@
<contentView:SeparatorCutStartView/>
<contentView:DetailsLivreButtonView ButtonTitle="Supprimer le livre"
ButtonCommand="{Binding DetailsLivreVM.Manager.RemoveBookCommand}"
ButtonCommand="{Binding DetailsLivreVM.RemoveBookCommand}"
ButtonCommandParameter="{Binding DetailsLivreVM.Book}"/>
</VerticalStackLayout>

@ -1,4 +1,5 @@
using PersonalMVVMToolkit;
using CommunityToolkit.Maui.Alerts;
using PersonalMVVMToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
@ -38,6 +39,8 @@ namespace LivreLand.ViewModel
public ICommand AddContactDataFormCommand { get; private set; }
public ICommand BookLendedCommand { get; private set; }
#endregion
#region Constructor
@ -47,6 +50,7 @@ namespace LivreLand.ViewModel
Navigator = navigatorVM;
Manager = managerVM;
AddContactDataFormCommand = new RelayCommand(() => AddContactDataForm());
BookLendedCommand = new RelayCommand<ContactVM>((contactVM) => BookLended(contactVM));
}
#endregion
@ -58,6 +62,16 @@ namespace LivreLand.ViewModel
DataFormIsVisible = true;
}
private async Task BookLended(ContactVM contactVM)
{
Manager.LendBookCommand.Execute(contactVM);
var toast = Toast.Make("Livre prêté !", CommunityToolkit.Maui.Core.ToastDuration.Short);
await toast.Show();
Navigator.PopupBackButtonNavigationCommand.Execute(null);
}
#endregion
}
}

@ -1,4 +1,5 @@
using PersonalMVVMToolkit;
using CommunityToolkit.Maui.Alerts;
using PersonalMVVMToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
@ -40,6 +41,12 @@ namespace LivreLand.ViewModel
public ICommand ShowPickerCommand { get; private set; }
public ICommand AddBookToFavoritesCommand { get; private set; }
public ICommand AddBookToReadListCommand { get; private set; }
public ICommand RemoveBookCommand { get; private set; }
#endregion
#region Constructor
@ -50,6 +57,9 @@ namespace LivreLand.ViewModel
Navigator = navigatorVM;
Book = bookVM;
ShowPickerCommand = new RelayCommand(() => ShowPicker());
AddBookToFavoritesCommand = new RelayCommand<BookVM>((bookVM) => AddBookToFavorites(bookVM));
AddBookToReadListCommand = new RelayCommand<BookVM>((bookVM) => AddBookToReadList(bookVM));
RemoveBookCommand = new RelayCommand<BookVM>((bookVM) => RemoveBook(bookVM));
}
#endregion
@ -61,6 +71,36 @@ namespace LivreLand.ViewModel
IsPickerVisible = true;
}
private async Task AddBookToFavorites(BookVM bookVM)
{
Manager.AddToFavoritesCommand.Execute(bookVM);
var toast = Toast.Make("Livre ajouté aux favoris !", CommunityToolkit.Maui.Core.ToastDuration.Short);
await toast.Show();
Navigator.NavigationCommand.Execute("/favoris");
}
private async Task AddBookToReadList(BookVM bookVM)
{
Manager.UpdateToBeReadBookCommand.Execute(bookVM);
var toast = Toast.Make("Livre ajouté à la liste À lire plus tard !", CommunityToolkit.Maui.Core.ToastDuration.Short);
await toast.Show();
Navigator.NavigationCommand.Execute("/later");
}
private async Task RemoveBook(BookVM bookVM)
{
Manager.RemoveBookCommand.Execute(bookVM);
var toast = Toast.Make("Livre supprimé !", CommunityToolkit.Maui.Core.ToastDuration.Short);
await toast.Show();
Navigator.PopupBackButtonNavigationCommand.Execute(null);
}
#endregion
}
}

Loading…
Cancel
Save