Skip to content

Commit

Permalink
Fixed source priority lists going out of sync
Browse files Browse the repository at this point in the history
  • Loading branch information
DSPaul committed Oct 24, 2024
1 parent a54c6eb commit f919018
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/Models/CodexProperties/CodexProperty.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
using CommunityToolkit.Mvvm.ComponentModel;
using COMPASS.Tools;
using COMPASS.ViewModels.Sources;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace COMPASS.Models.CodexProperties
{
public abstract class CodexProperty : ObservableObject
public abstract class CodexProperty : ObservableObject, IDisposable
{
protected CodexProperty(string propName, string? label = null)
{
Name = propName;
Label = label ?? propName;
_defaultSourcePriority = GetDefaultSources(propName);
UpdateSources();

SourcePriorityNamed = new(SourcePriority.Select(source => new NamedMetaDataSource(source)));
SourcePriorityNamed.CollectionChanged += SourcePriorityNamed_CollectionChanged;
}

private void SourcePriorityNamed_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
=> SourcePriority = SourcePriorityNamed.Select(spn => spn.Source).ToList();

#region Properties

public string Name { get; init; }
Expand Down Expand Up @@ -45,12 +52,10 @@ protected CodexProperty(string propName, string? label = null)

private readonly List<MetaDataSource> _defaultSourcePriority;

private ObservableCollection<NamedMetaDataSource>? _sourcePriorityNamed;
/// <summary>
/// Ordered List of sources that can set this prop, named for data binding
/// </summary>
public ObservableCollection<NamedMetaDataSource> SourcePriorityNamed =>
_sourcePriorityNamed ??= new(SourcePriority.Select(source => new NamedMetaDataSource(source)));
public ObservableCollection<NamedMetaDataSource> SourcePriorityNamed { get; }

private List<MetaDataSource> _sourcePriority = new();
/// <summary>
Expand Down Expand Up @@ -176,6 +181,7 @@ public void UpdateSources()
},
_ => new(),
};
public void Dispose() => SourcePriorityNamed.CollectionChanged -= SourcePriorityNamed_CollectionChanged;

#endregion
}
Expand Down
2 changes: 1 addition & 1 deletion src/ViewModels/FilterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public CodexProperty SelectedNotEmptyProperty
}
}

public List<CodexProperty> PossibleEmptyProperties { get; } = new()
public static List<CodexProperty> PossibleEmptyProperties { get; } = new()
{
CodexProperty.GetInstance(nameof(Codex.Authors))!,
CodexProperty.GetInstance(nameof(Codex.CoverArt))!,
Expand Down

0 comments on commit f919018

Please sign in to comment.