From 6daa5ec788313fda88d1cd3f33b7a460f9a18de6 Mon Sep 17 00:00:00 2001 From: AL <26797547+Al12rs@users.noreply.github.com> Date: Thu, 12 Sep 2024 14:55:50 +0200 Subject: [PATCH] Fix Collections constantly getting added --- .../LeftMenu/Loadout/LoadoutLeftMenuViewModel.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/NexusMods.App.UI/LeftMenu/Loadout/LoadoutLeftMenuViewModel.cs b/src/NexusMods.App.UI/LeftMenu/Loadout/LoadoutLeftMenuViewModel.cs index 7616bed896..91ea0ebb88 100644 --- a/src/NexusMods.App.UI/LeftMenu/Loadout/LoadoutLeftMenuViewModel.cs +++ b/src/NexusMods.App.UI/LeftMenu/Loadout/LoadoutLeftMenuViewModel.cs @@ -25,7 +25,9 @@ public class LoadoutLeftMenuViewModel : AViewModel, I public IApplyControlViewModel ApplyControlViewModel { get; } private readonly SourceList _items = new(); - private ReadOnlyObservableCollection _finalCollection = new(new ObservableCollection()); + private ReadOnlyObservableCollection _finalCollection = new([]); + + private readonly SourceList _collectionGroupItems = new(); public ReadOnlyObservableCollection Items => _finalCollection; public WorkspaceId WorkspaceId { get; } @@ -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) @@ -148,6 +151,7 @@ public LoadoutLeftMenuViewModel( .DisposeWith(disposable); _items.Connect() + .Merge(_collectionGroupItems.Connect()) .Sort(new LeftMenuComparer()) .Bind(out _finalCollection) .Subscribe()