@implements IDisposable @inject NavigationManager NavigationManager @inject ISnackbar Snackbar @inject ILogger Logger @Name Media Source
Save Changes
@code { private CancellationTokenSource _cts; [Parameter] public string Name { get; set; } [Parameter] public Func> LoadSecrets { get; set; } [Parameter] public Func>> SaveSecrets { get; set; } private readonly RemoteMediaSourceEditViewModel _model = new(); private EditContext _editContext; private ValidationMessageStore _messageStore; public void Dispose() { _cts?.Cancel(); _cts?.Dispose(); } protected override async Task OnParametersSetAsync() { _cts?.Cancel(); _cts?.Dispose(); _cts = new CancellationTokenSource(); var token = _cts.Token; try { await LoadSecrets(_model, token); } catch (OperationCanceledException) { // do nothing } } protected override void OnInitialized() { _editContext = new EditContext(_model); _messageStore = new ValidationMessageStore(_editContext); } private async Task HandleSubmitAsync() { _messageStore.Clear(); if (_editContext.Validate()) { Either result = await SaveSecrets(_model, _cts.Token); result.Match( _ => NavigationManager.NavigateTo($"media/sources/{Name.ToLowerInvariant()}"), error => { Snackbar.Add(error.Value, Severity.Error); Logger.LogError("Error saving {MediaSource} secrets: {Error}", Name, error.Value); }); } } }