Nu fungerar Popupen och den går att stänga

This commit is contained in:
2025-10-17 11:52:01 +02:00
parent 21eb0d5498
commit bb8f4bd5ed
12 changed files with 272 additions and 23 deletions

View File

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="12.2.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
</ItemGroup>

View File

@ -0,0 +1,39 @@
using CommunityToolkit.Maui.Alerts;
using CommunityToolkit.Mvvm.ComponentModel;
namespace GreadyPoang.Core;
public partial class BaseViewModel : ObservableObject
{
[ObservableProperty]
private bool isBusy;
protected async Task RunAsyncCommand(Func<Task> action, string loadingMessage = null, string errorMessage = "Ett fel inträffade")
{
if (IsBusy) return;
try
{
IsBusy = true;
if (!string.IsNullOrWhiteSpace(loadingMessage))
await Snackbar.Make(
message: loadingMessage,
duration: TimeSpan.FromSeconds(2),
action: null).Show();
await action.Invoke();
}
catch (Exception ex)
{
await Snackbar.Make(
message: $"{errorMessage}: {ex.Message}",
duration: TimeSpan.FromSeconds(3),
action: () => Console.WriteLine("Åtgärd vald")).Show();
}
finally
{
IsBusy = false;
}
}
}