@page "/media/smart-collections/{Id:int}/edit" @using ErsatzTV.Application.MediaCollections @implements IDisposable @inject NavigationManager NavigationManager @inject ILogger Logger @inject ISnackbar Snackbar @inject IMediator Mediator Save Smart Collection
Smart Collection
Name
@code { private CancellationTokenSource _cts; [Parameter] public int Id { get; set; } private readonly SmartCollectionEditViewModel _model = new(); private MudForm _form; private bool _success; public void Dispose() { _cts?.Cancel(); _cts?.Dispose(); } protected override async Task OnParametersSetAsync() { _cts?.Cancel(); _cts?.Dispose(); _cts = new CancellationTokenSource(); var token = _cts.Token; try { Option maybeSmartCollection = await Mediator.Send(new GetSmartCollectionById(Id), token); foreach (SmartCollectionViewModel smartCollection in maybeSmartCollection) { _model.Id = smartCollection.Id; _model.Name = smartCollection.Name; _model.Query = smartCollection.Query; } } catch (OperationCanceledException) { // do nothing } } private async Task HandleSubmitAsync() { await _form.Validate(); if (_success) { Either result = await Mediator.Send(new UpdateSmartCollection(Id, _model.Name, _model.Query), _cts.Token); result.Match( _ => NavigationManager.NavigateTo("media/smart-collections"), error => { Snackbar.Add(error.Value, Severity.Error); Logger.LogError("Error saving smart collection: {Error}", error.Value); }); } } }