From 28a65e74bb6344cde7ef6b77aee51546e35c88f6 Mon Sep 17 00:00:00 2001
From: Jason Dove <1695733+jasongdove@users.noreply.github.com>
Date: Thu, 10 Jul 2025 11:48:20 +0000
Subject: [PATCH] use new form layout for local library editor (#2129)
---
CHANGELOG.md | 1 +
ErsatzTV/Pages/ChannelEditor.razor | 2 +-
ErsatzTV/Pages/LocalLibraryEditor.razor | 157 ++++++++++--------
.../LocalLibraryEditViewModelValidator.cs | 9 -
.../LocalLibraryPathEditViewModelValidator.cs | 13 --
5 files changed, 89 insertions(+), 93 deletions(-)
delete mode 100644 ErsatzTV/Validators/LocalLibraryEditViewModelValidator.cs
delete mode 100644 ErsatzTV/Validators/LocalLibraryPathEditViewModelValidator.cs
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 590606f4..613e1544 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -78,6 +78,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- FFmpeg Profile editor
- Schedule editor
- Watermark editor
+ - Local library editor
### Fixed
- Fix QSV acceleration in docker with older Intel devices
diff --git a/ErsatzTV/Pages/ChannelEditor.razor b/ErsatzTV/Pages/ChannelEditor.razor
index d3beba28..914b8dcd 100644
--- a/ErsatzTV/Pages/ChannelEditor.razor
+++ b/ErsatzTV/Pages/ChannelEditor.razor
@@ -24,7 +24,7 @@
- @(IsEdit ? "Edit Channel" : "Add Channel")
+ Channel
diff --git a/ErsatzTV/Pages/LocalLibraryEditor.razor b/ErsatzTV/Pages/LocalLibraryEditor.razor
index d6cd6679..e5318750 100644
--- a/ErsatzTV/Pages/LocalLibraryEditor.razor
+++ b/ErsatzTV/Pages/LocalLibraryEditor.razor
@@ -9,68 +9,79 @@
@inject ISnackbar Snackbar
@inject NavigationManager NavigationManager
-
-
- @(IsEdit ? "Edit Local Library" : "Add Local Library")
-
-
-
-
-
-
-
- @foreach (LibraryMediaKind mediaKind in Enum.GetValues())
- {
- @mediaKind
- }
-
-
-
-
-
- Add Path
-
-
- Save Changes
-
-
-
-
-
-
-
-
- Library Paths
-
-
-
-
-
-
- Path
-
-
-
- @context.Path
-
-
-
-
-
-
-
-
-
-
+
+
+ @(IsEdit ? "Save Local Library" : "Add Local Library")
+
+
+
+ Local Library
+
+
+
+ Name
-
-
-
-
-
+
+
+
+
+ Media Kind
+
+
+ @foreach (LibraryMediaKind mediaKind in Enum.GetValues())
+ {
+ @mediaKind
+ }
+
+
+
+
+ Path
+
+
+
+
+
+
+ Add Path
+
+
+
+
+ Library Paths
+
+
+
+
+
+
+
+
+ Path
+
+
+
+ @context.Path
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@code {
private readonly CancellationTokenSource _cts = new();
@@ -80,8 +91,7 @@
private readonly LocalLibraryEditViewModel _model = new();
private readonly LocalLibraryPathEditViewModel _newPath = new();
- private EditContext _editContext;
- private ValidationMessageStore _messageStore;
+ private bool _success;
private bool IsEdit => Id != 0;
@@ -117,9 +127,6 @@
protected override void OnInitialized()
{
Locker.OnLibraryChanged += LockChanged;
-
- _editContext = new EditContext(_model);
- _messageStore = new ValidationMessageStore(_editContext);
}
private void LockChanged(object sender, EventArgs e) =>
@@ -143,7 +150,7 @@
IDialogReference dialog = await Dialog.ShowAsync
("Move Local Library Path", parameters, options);
DialogResult result = await dialog.Result;
- if (!result.Canceled && result.Data is LocalLibraryViewModel library)
+ if (result is { Canceled: false, Data: LocalLibraryViewModel library })
{
var request = new MoveLocalLibraryPath(libraryPath.Id, library.Id);
Either moveResult = await Mediator.Send(request, _cts.Token);
@@ -177,7 +184,7 @@
IDialogReference dialog = await Dialog.ShowAsync("Delete Library Path", parameters, options);
DialogResult result = await dialog.Result;
- if (!result.Canceled)
+ if (result is { Canceled: false })
{
_model.HasChanges = true;
_model.Paths.Remove(libraryPath);
@@ -186,6 +193,17 @@
private void AddLibraryPath()
{
+ if (string.IsNullOrWhiteSpace(_newPath.Path))
+ {
+ return;
+ }
+
+ if (!Directory.Exists(_newPath.Path))
+ {
+ Snackbar.Add("Path must exist on filesystem", Severity.Error);
+ return;
+ }
+
if (!string.IsNullOrWhiteSpace(_newPath.Path) && _model.Paths.All(p => NormalizePath(p.Path) != NormalizePath(_newPath.Path)))
{
_model.HasChanges = true;
@@ -201,8 +219,7 @@
private async Task SaveChangesAsync()
{
- _messageStore.Clear();
- if (_editContext.Validate())
+ if (_success)
{
Either result = IsEdit
? await Mediator.Send(
diff --git a/ErsatzTV/Validators/LocalLibraryEditViewModelValidator.cs b/ErsatzTV/Validators/LocalLibraryEditViewModelValidator.cs
deleted file mode 100644
index e31c999d..00000000
--- a/ErsatzTV/Validators/LocalLibraryEditViewModelValidator.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using ErsatzTV.ViewModels;
-using FluentValidation;
-
-namespace ErsatzTV.Validators;
-
-public class LocalLibraryEditViewModelValidator : AbstractValidator
-{
- public LocalLibraryEditViewModelValidator() => RuleFor(c => c.Name).NotEmpty();
-}
diff --git a/ErsatzTV/Validators/LocalLibraryPathEditViewModelValidator.cs b/ErsatzTV/Validators/LocalLibraryPathEditViewModelValidator.cs
deleted file mode 100644
index 102b953f..00000000
--- a/ErsatzTV/Validators/LocalLibraryPathEditViewModelValidator.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using ErsatzTV.ViewModels;
-using FluentValidation;
-
-namespace ErsatzTV.Validators;
-
-public class LocalLibraryPathEditViewModelValidator : AbstractValidator
-{
- public LocalLibraryPathEditViewModelValidator()
- {
- RuleFor(x => x.Path).NotEmpty();
- RuleFor(x => x.Path).Must(Directory.Exists).WithMessage("Path must exist on filesystem");
- }
-}