mirror of
https://github.com/gwdevhub/Daybreak.git
synced 2026-07-24 12:06:34 +00:00
38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
using Daybreak.Shared.Models.Options;
|
|
using Daybreak.Shared.Services.Options;
|
|
using TrailBlazr.ViewModels;
|
|
|
|
namespace Daybreak.Views;
|
|
|
|
public sealed class OptionViewModel(IOptionsProvider optionsProvider)
|
|
: ViewModelBase<OptionViewModel, OptionView>
|
|
{
|
|
private readonly IOptionsProvider optionsProvider = optionsProvider;
|
|
|
|
public OptionInstance? OptionInstance
|
|
{
|
|
get => field;
|
|
set
|
|
{
|
|
field = value;
|
|
this.NotifyPropertyChanged(nameof(this.OptionInstance));
|
|
}
|
|
}
|
|
|
|
public override ValueTask ParametersSet(OptionView view, CancellationToken cancellationToken)
|
|
{
|
|
this.OptionInstance = this.optionsProvider.GetRegisteredOptionInstance(view.OptionName ?? string.Empty);
|
|
return base.ParametersSet(view, cancellationToken);
|
|
}
|
|
|
|
public void OnValueChanged()
|
|
{
|
|
if (this.OptionInstance is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
this.optionsProvider.SaveRegisteredOptions(this.OptionInstance);
|
|
}
|
|
}
|