Skip to content

Commit

Permalink
Fix Collections constantly getting added
Browse files Browse the repository at this point in the history
  • Loading branch information
Al12rs committed Sep 12, 2024
1 parent 5360a8d commit 6daa5ec
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public class LoadoutLeftMenuViewModel : AViewModel<ILoadoutLeftMenuViewModel>, I
public IApplyControlViewModel ApplyControlViewModel { get; }

private readonly SourceList<ILeftMenuItemViewModel> _items = new();
private ReadOnlyObservableCollection<ILeftMenuItemViewModel> _finalCollection = new(new ObservableCollection<ILeftMenuItemViewModel>());
private ReadOnlyObservableCollection<ILeftMenuItemViewModel> _finalCollection = new([]);

private readonly SourceList<ILeftMenuItemViewModel> _collectionGroupItems = new();

public ReadOnlyObservableCollection<ILeftMenuItemViewModel> Items => _finalCollection;
public WorkspaceId WorkspaceId { get; }
Expand Down Expand Up @@ -124,13 +126,14 @@ public LoadoutLeftMenuViewModel(

this.WhenActivated(disposable =>
{
_collectionGroupItems.Clear();
CollectionGroup.ObserveAll(conn)
.Filter(f => f.AsLoadoutItemGroup().AsLoadoutItem().LoadoutId == loadoutContext.LoadoutId)
.SortBy(itm => itm.IsReadOnly)
.Transform(itm => MakeLoadoutItemGroupViewModel(workspaceController, itm, serviceProvider))
.Subscribe(s =>
{
_items.Edit(x => {
_collectionGroupItems.Edit(x => {
foreach (var change in s)
{
if (change.Reason == ChangeReason.Add)
Expand All @@ -148,6 +151,7 @@ public LoadoutLeftMenuViewModel(
.DisposeWith(disposable);

_items.Connect()
.Merge(_collectionGroupItems.Connect())
.Sort(new LeftMenuComparer())
.Bind(out _finalCollection)
.Subscribe()
Expand Down

0 comments on commit 6daa5ec

Please sign in to comment.