Skip to content

Commit

Permalink
Switch from alerts to toasts for cart notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
akv3sic committed Nov 5, 2023
1 parent cd9a640 commit a44bc1f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 10 additions & 1 deletion MauiStoreApp/ViewModels/CartViewModel.cs
Expand Up @@ -6,6 +6,8 @@

using System.Collections.ObjectModel;
using System.Diagnostics;
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Maui.Core;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using MauiStoreApp.Models;
Expand Down Expand Up @@ -160,7 +162,14 @@ public async Task DeleteCart()
{
Debug.WriteLine("Cart deleted.");
CartItems.Clear();
await Shell.Current.DisplayAlert("Obavijest", "Košarica je uspješno obrisana.", "U redu");

CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

string infoText = "Košarica uspješno izbrisana.";
ToastDuration duration = ToastDuration.Short;
var toast = Toast.Make(infoText, duration);

await toast.Show(cancellationTokenSource.Token);
}
else
{
Expand Down
10 changes: 9 additions & 1 deletion MauiStoreApp/ViewModels/ProductDetailsViewModel.cs
Expand Up @@ -6,6 +6,8 @@

using System.Collections.ObjectModel;
using System.Diagnostics;
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Maui.Core;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using MauiStoreApp.Models;
Expand Down Expand Up @@ -185,7 +187,13 @@ private async Task AddToCart(Product product)

_cartService.AddProductToCart(product);

await Shell.Current.DisplayAlert("Obavijest", "Proizvod je dodan u košaricu.", "U redu");
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

string infoText = "Proizvod dodan u košaricu.";
ToastDuration duration = ToastDuration.Short;
var toast = Toast.Make(infoText, duration);

await toast.Show(cancellationTokenSource.Token);
}
catch (Exception ex)
{
Expand Down

0 comments on commit a44bc1f

Please sign in to comment.