Skip to content

Instantly share code, notes, and snippets.

@beginnerapps
Created February 18, 2024 17:14
Show Gist options
  • Save beginnerapps/b0f5f3f2bb2ca22032931a368c800749 to your computer and use it in GitHub Desktop.
Save beginnerapps/b0f5f3f2bb2ca22032931a368c800749 to your computer and use it in GitHub Desktop.
StartupPageViewModel
using BingoMania.Framework.Views;
using Dawn;
using Microsoft.Maui.Controls;
using ReactiveUI;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading.Tasks;
namespace BingoMania.Features.Startup
{
public sealed class StartupPageViewModel : ViewModelBase
{
public IReactiveCommand StartCommand { get; }
public StartupPageViewModel(IStartupSequencer startupSequencer, INavigation navigation)
: base(navigation)
{
_startupSequencer = Guard.Argument(startupSequencer, nameof(startupSequencer))
.NotNull()
.Value;
//Disable the Button once it is started!
var canStart = _startupSequencer.IsInProgress
.StartWith(false)
.Select(x => !x);
StartCommand = ReactiveCommand.CreateFromTask(ExecuteStartCommand, canStart)
.DisposeWith(TrashBin); //Dispose the Command when ViewModel will be disposed!
}
private async Task ExecuteStartCommand()
{
var result = await _startupSequencer.Run();
if (result)
{
//Continue to load Home Page!
}
else
{
//Show the Error or whatever
}
}
private readonly IStartupSequencer _startupSequencer;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment