UX Overhaul Part 2 (#3112)

Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
This commit is contained in:
Joe Milazzo 2024-08-16 19:37:12 -05:00 committed by GitHub
parent 0247bc5012
commit 3d8aa2ad24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
192 changed files with 14808 additions and 1874 deletions

View file

@ -108,4 +108,49 @@ public static class GenreHelper
onModified();
}
}
public static void UpdateGenreList(ICollection<GenreTagDto>? tags, Chapter chapter,
IReadOnlyCollection<Genre> allTags, Action<Genre> handleAdd, Action onModified)
{
// TODO: Write some unit tests
if (tags == null) return;
var isModified = false;
// I want a union of these 2 lists. Return only elements that are in both lists, but the list types are different
var existingTags = chapter.Genres.ToList();
foreach (var existing in existingTags)
{
if (tags.SingleOrDefault(t => t.Title.ToNormalized().Equals(existing.NormalizedTitle)) == null)
{
// Remove tag
chapter.Genres.Remove(existing);
isModified = true;
}
}
// At this point, all tags that aren't in dto have been removed.
foreach (var tagTitle in tags.Select(t => t.Title))
{
var normalizedTitle = tagTitle.ToNormalized();
var existingTag = allTags.SingleOrDefault(t => t.NormalizedTitle.Equals(normalizedTitle));
if (existingTag != null)
{
if (chapter.Genres.All(t => !t.NormalizedTitle.Equals(normalizedTitle)))
{
handleAdd(existingTag);
isModified = true;
}
}
else
{
// Add new tag
handleAdd(new GenreBuilder(tagTitle).Build());
isModified = true;
}
}
if (isModified)
{
onModified();
}
}
}

View file

@ -165,18 +165,76 @@ public static class PersonHelper
}
}
public static bool HasAnyPeople(SeriesMetadataDto? seriesMetadata)
public static void UpdatePeopleList(PersonRole role, ICollection<PersonDto>? people, Chapter chapter, IReadOnlyCollection<Person> allPeople,
Action<Person> handleAdd, Action onModified)
{
if (seriesMetadata == null) return false;
return seriesMetadata.Writers.Any() ||
seriesMetadata.CoverArtists.Any() ||
seriesMetadata.Publishers.Any() ||
seriesMetadata.Characters.Any() ||
seriesMetadata.Pencillers.Any() ||
seriesMetadata.Inkers.Any() ||
seriesMetadata.Colorists.Any() ||
seriesMetadata.Letterers.Any() ||
seriesMetadata.Editors.Any() ||
seriesMetadata.Translators.Any();
if (people == null) return;
var isModified = false;
// I want a union of these 2 lists. Return only elements that are in both lists, but the list types are different
var existingTags = chapter.People.Where(p => p.Role == role).ToList();
foreach (var existing in existingTags)
{
if (people.SingleOrDefault(t => t.Id == existing.Id) == null) // This needs to check against role
{
// Remove tag
chapter.People.Remove(existing);
isModified = true;
}
}
// At this point, all tags that aren't in dto have been removed.
foreach (var tag in people)
{
var existingTag = allPeople.FirstOrDefault(t => t.Name == tag.Name && t.Role == tag.Role);
if (existingTag != null)
{
if (chapter.People.Where(t => t.Role == tag.Role).All(t => t.Name != null && !t.Name.Equals(tag.Name)))
{
handleAdd(existingTag);
isModified = true;
}
}
else
{
// Add new tag
handleAdd(new PersonBuilder(tag.Name, role).Build());
isModified = true;
}
}
if (isModified)
{
onModified();
}
}
public static bool HasAnyPeople(SeriesMetadataDto? dto)
{
if (dto == null) return false;
return dto.Writers.Count != 0 ||
dto.CoverArtists.Count != 0 ||
dto.Publishers.Count != 0 ||
dto.Characters.Count != 0 ||
dto.Pencillers.Count != 0 ||
dto.Inkers.Count != 0 ||
dto.Colorists.Count != 0 ||
dto.Letterers.Count != 0 ||
dto.Editors.Count != 0 ||
dto.Translators.Count != 0;
}
public static bool HasAnyPeople(UpdateChapterDto? dto)
{
if (dto == null) return false;
return dto.Writers.Count != 0 ||
dto.CoverArtists.Count != 0 ||
dto.Publishers.Count != 0 ||
dto.Characters.Count != 0 ||
dto.Pencillers.Count != 0 ||
dto.Inkers.Count != 0 ||
dto.Colorists.Count != 0 ||
dto.Letterers.Count != 0 ||
dto.Editors.Count != 0 ||
dto.Translators.Count != 0;
}
}

View file

@ -151,6 +151,48 @@ public static class TagHelper
onModified();
}
}
public static void UpdateTagList(ICollection<TagDto>? tags, Chapter chapter, IReadOnlyCollection<Tag> allTags, Action<Tag> handleAdd, Action onModified)
{
if (tags == null) return;
var isModified = false;
// I want a union of these 2 lists. Return only elements that are in both lists, but the list types are different
var existingTags = chapter.Tags.ToList();
foreach (var existing in existingTags.Where(existing => tags.SingleOrDefault(t => t.Id == existing.Id) == null))
{
// Remove tag
chapter.Tags.Remove(existing);
isModified = true;
}
// At this point, all tags that aren't in dto have been removed.
foreach (var tagTitle in tags.Select(t => t.Title))
{
var normalizedTitle = tagTitle.ToNormalized();
var existingTag = allTags.SingleOrDefault(t => t.NormalizedTitle.Equals(normalizedTitle));
if (existingTag != null)
{
if (chapter.Tags.All(t => t.NormalizedTitle != normalizedTitle))
{
handleAdd(existingTag);
isModified = true;
}
}
else
{
// Add new tag
handleAdd(new TagBuilder(tagTitle).Build());
isModified = true;
}
}
if (isModified)
{
onModified();
}
}
}
#nullable disable