From b84bb6b437a1f898f5c0f5f3f02cf747596c390a Mon Sep 17 00:00:00 2001 From: Jason Dove <1695733+jasongdove@users.noreply.github.com> Date: Tue, 15 Aug 2023 06:39:29 -0500 Subject: [PATCH] fix ui crashes (#1382) * fix ffmpeg editor crash * fix watermark editor * fix multi collection editor * fix filler preset editor crash --- ErsatzTV/Pages/FFmpegEditor.razor | 58 ++++- ErsatzTV/Pages/FillerPresetEditor.razor | 229 ++++++++--------- ErsatzTV/Pages/MultiCollectionEditor.razor | 104 ++++---- ErsatzTV/Pages/WatermarkEditor.razor | 273 +++++++++++---------- 4 files changed, 358 insertions(+), 306 deletions(-) diff --git a/ErsatzTV/Pages/FFmpegEditor.razor b/ErsatzTV/Pages/FFmpegEditor.razor index 6e89752cd..6772ae304 100644 --- a/ErsatzTV/Pages/FFmpegEditor.razor +++ b/ErsatzTV/Pages/FFmpegEditor.razor @@ -11,9 +11,12 @@ @inject ISnackbar _snackbar @inject IMediator _mediator @inject IMemoryCache _memoryCache +@inject PersistentComponentState ApplicationState - + @if (_editContext is not null) + { + @@ -139,6 +142,7 @@ + } @code { @@ -151,25 +155,55 @@ private EditContext _editContext; private ValidationMessageStore _messageStore; - private List _resolutions; - private List _vaapiDevices; + private List _resolutions = new(); + private List _vaapiDevices = new(); + private PersistingComponentStateSubscription _persistingSubscription; public void Dispose() { + _persistingSubscription.Dispose(); + _cts.Cancel(); _cts.Dispose(); } + + protected override Task OnInitializedAsync() + { + _persistingSubscription = ApplicationState.RegisterOnPersisting(PersistData); + + return base.OnInitializedAsync(); + } protected override async Task OnParametersSetAsync() { - _resolutions = await _mediator.Send(new GetAllResolutions(), _cts.Token); + if (!ApplicationState.TryTakeFromJson("_resolutions", out List restoredResolutions)) + { + _resolutions = await _mediator.Send(new GetAllResolutions(), _cts.Token); + } + else + { + _resolutions = restoredResolutions; + } if (IsEdit) { - Option profile = await _mediator.Send(new GetFFmpegProfileById(Id), _cts.Token); - profile.Match( - ffmpegProfileViewModel => _model = new FFmpegProfileEditViewModel(ffmpegProfileViewModel), - () => _navigationManager.NavigateTo("404")); + if (!ApplicationState.TryTakeFromJson("_model", out FFmpegProfileEditViewModel restoredProfile)) + { + Option maybeProfile = await _mediator.Send(new GetFFmpegProfileById(Id), _cts.Token); + foreach (FFmpegProfileViewModel profile in maybeProfile) + { + _model = new FFmpegProfileEditViewModel(profile); + } + + if (maybeProfile.IsNone) + { + _navigationManager.NavigateTo("404"); + } + } + else + { + _model = restoredProfile; + } } else { @@ -186,6 +220,14 @@ _vaapiDevices = vaapiDevices.OrderBy(s => s).ToList(); } + + private Task PersistData() + { + ApplicationState.PersistAsJson("_model", _model); + ApplicationState.PersistAsJson("_resolutions", _resolutions); + + return Task.CompletedTask; + } private bool IsEdit => Id != 0; diff --git a/ErsatzTV/Pages/FillerPresetEditor.razor b/ErsatzTV/Pages/FillerPresetEditor.razor index 7027d47f0..b421d6f21 100644 --- a/ErsatzTV/Pages/FillerPresetEditor.razor +++ b/ErsatzTV/Pages/FillerPresetEditor.razor @@ -16,119 +16,122 @@
@(IsEdit ? "Edit Filler Preset" : "Add Filler Preset") - - - - - - - Pre-Roll - Mid-Roll - Post-Roll - Tail - Fallback - - - Duration - Count - Pad - - - - - 5 (:00, :05, :10, :15, :20, etc) - 10 (:00, :10, :20, :30, :40, :50) - 15 (:00, :15, :30, :45) - 30 (:00, :30) - - - - @foreach (ProgramScheduleItemCollectionType collectionType in Enum.GetValues()) - { - @collectionType - } - - @if (_model.CollectionType == ProgramScheduleItemCollectionType.Collection) - { - - @foreach (MediaCollectionViewModel collection in _mediaCollections) - { - @collection.Name - } - - } - @if (_model.CollectionType == ProgramScheduleItemCollectionType.MultiCollection) - { - - @foreach (MultiCollectionViewModel collection in _multiCollections) - { - @collection.Name - } + @if (_editContext is not null) + { + + + + + + + Pre-Roll + Mid-Roll + Post-Roll + Tail + Fallback - } - @if (_model.CollectionType == ProgramScheduleItemCollectionType.SmartCollection) - { - - @foreach (SmartCollectionViewModel collection in _smartCollections) - { - @collection.Name - } + + Duration + Count + Pad - } - @if (_model.CollectionType == ProgramScheduleItemCollectionType.TelevisionShow) - { - - @foreach (NamedMediaItemViewModel show in _televisionShows) - { - @show.Name - } - - } - @if (_model.CollectionType == ProgramScheduleItemCollectionType.TelevisionSeason) - { - - @foreach (NamedMediaItemViewModel season in _televisionSeasons) - { - @season.Name - } + + + + 5 (:00, :05, :10, :15, :20, etc) + 10 (:00, :10, :20, :30, :40, :50) + 15 (:00, :15, :30, :45) + 30 (:00, :30) - } - @if (_model.CollectionType == ProgramScheduleItemCollectionType.Artist) - { - - @foreach (NamedMediaItemViewModel artist in _artists) + + + @foreach (ProgramScheduleItemCollectionType collectionType in Enum.GetValues()) { - @artist.Name + @collectionType } - } - - - - @(IsEdit ? "Save Changes" : "Add Filler Preset") - - - - + @if (_model.CollectionType == ProgramScheduleItemCollectionType.Collection) + { + + @foreach (MediaCollectionViewModel collection in _mediaCollections) + { + @collection.Name + } + + } + @if (_model.CollectionType == ProgramScheduleItemCollectionType.MultiCollection) + { + + @foreach (MultiCollectionViewModel collection in _multiCollections) + { + @collection.Name + } + + } + @if (_model.CollectionType == ProgramScheduleItemCollectionType.SmartCollection) + { + + @foreach (SmartCollectionViewModel collection in _smartCollections) + { + @collection.Name + } + + } + @if (_model.CollectionType == ProgramScheduleItemCollectionType.TelevisionShow) + { + + @foreach (NamedMediaItemViewModel show in _televisionShows) + { + @show.Name + } + + } + @if (_model.CollectionType == ProgramScheduleItemCollectionType.TelevisionSeason) + { + + @foreach (NamedMediaItemViewModel season in _televisionSeasons) + { + @season.Name + } + + } + @if (_model.CollectionType == ProgramScheduleItemCollectionType.Artist) + { + + @foreach (NamedMediaItemViewModel artist in _artists) + { + @artist.Name + } + + } + + + + @(IsEdit ? "Save Changes" : "Add Filler Preset") + + + + + }
@@ -142,12 +145,12 @@ private EditContext _editContext; private ValidationMessageStore _messageStore; - private List _mediaCollections; - private List _multiCollections; - private List _smartCollections; - private List _televisionShows; - private List _televisionSeasons; - private List _artists; + private List _mediaCollections = new(); + private List _multiCollections = new(); + private List _smartCollections = new(); + private List _televisionShows = new(); + private List _televisionSeasons = new(); + private List _artists = new(); public void Dispose() { diff --git a/ErsatzTV/Pages/MultiCollectionEditor.razor b/ErsatzTV/Pages/MultiCollectionEditor.razor index 332a8845d..a0941abfa 100644 --- a/ErsatzTV/Pages/MultiCollectionEditor.razor +++ b/ErsatzTV/Pages/MultiCollectionEditor.razor @@ -11,53 +11,56 @@
@(IsEdit ? "Edit Multi Collection" : "Add Multi Collection") - - - - - - - @foreach (MediaCollectionViewModel collection in _collections) - { - - @collection.Name - - } - - - Add Collection - - - @foreach (SmartCollectionViewModel collection in _smartCollections) - { - - @collection.Name - - } - - - Add Smart Collection - - - - - @(IsEdit ? "Save Changes" : "Add Multi Collection") - - - - + @if (_editContext is not null) + { + + + + + + + @foreach (MediaCollectionViewModel collection in _collections) + { + + @collection.Name + + } + + + Add Collection + + + @foreach (SmartCollectionViewModel collection in _smartCollections) + { + + @collection.Name + + } + + + Add Smart Collection + + + + + @(IsEdit ? "Save Changes" : "Add Multi Collection") + + + + + }
@@ -108,11 +111,12 @@ [Parameter] public int Id { get; set; } - private readonly MultiCollectionEditViewModel _model = new(); + private readonly MultiCollectionEditViewModel _model = + new() { Items = new List() }; private EditContext _editContext; private ValidationMessageStore _messageStore; - private List _collections; - private List _smartCollections; + private List _collections = new(); + private List _smartCollections = new(); private MediaCollectionViewModel _selectedCollection; private SmartCollectionViewModel _selectedSmartCollection; private MudSelect _collectionSelect; diff --git a/ErsatzTV/Pages/WatermarkEditor.razor b/ErsatzTV/Pages/WatermarkEditor.razor index 88e828435..0ba335ce8 100644 --- a/ErsatzTV/Pages/WatermarkEditor.razor +++ b/ErsatzTV/Pages/WatermarkEditor.razor @@ -11,141 +11,144 @@
- - - - - - @(IsEdit ? "Edit Watermark" : "Add Watermark") - - - - - - None - Permanent - Intermittent - - - Custom - Channel Logo - - - - - - - Upload Image - - - - - Bottom Right - Bottom Middle - Bottom Left - Left Middle - Top Left - Top Middle - Top Right - Right Middle - - - - - - Scaled - Actual Size - - - - - - - - - - - - - - - - - - 5 minutes - 10 minutes - 15 minutes - 20 minutes - 30 minutes - 60 minutes - - - - - - - - - - - - - - - - @(IsEdit ? "Save Changes" : "Add Watermark") - - - - + @if (_editContext is not null) + { + + + + + + @(IsEdit ? "Edit Watermark" : "Add Watermark") + + + + + + None + Permanent + Intermittent + + + Custom + Channel Logo + + + + + + + Upload Image + + + + + Bottom Right + Bottom Middle + Bottom Left + Left Middle + Top Left + Top Middle + Top Right + Right Middle + + + + + + Scaled + Actual Size + + + + + + + + + + + + + + + + + + 5 minutes + 10 minutes + 15 minutes + 20 minutes + 30 minutes + 60 minutes + + + + + + + + + + + + + + + + @(IsEdit ? "Save Changes" : "Add Watermark") + + + + + }