-
-
-
-
-
-
-
-
+
+
+ @(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");
- }
-}