Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix data not being initialized for some rows in LoadoutView when fast scrolling through #2079

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,22 @@ public class FakeParentLoadoutItemModel : LoadoutItemModel
{
public required IObservable<DateTime> InstalledAtObservable { get; init; }

public required IObservable<IChangeSet<LoadoutItemId, EntityId>> LoadoutItemIdsObservable { get; init; }
public IObservable<IChangeSet<LoadoutItemId, EntityId>> LoadoutItemIdsObservable { get; }
public ObservableHashSet<LoadoutItemId> LoadoutItemIds { get; private set; } = [];

public override IReadOnlyCollection<LoadoutItemId> GetLoadoutItemIds() => LoadoutItemIds;

private readonly IDisposable _modelActivationDisposable;
private readonly SerialDisposable _loadoutItemIdsDisposable = new();
private readonly IDisposable _loadoutItemIdsDisposable;

public FakeParentLoadoutItemModel() : base(default(LoadoutItemId))
public FakeParentLoadoutItemModel(IObservable<IChangeSet<LoadoutItemId, EntityId>> loadoutItemIdsObservable) : base(default(LoadoutItemId))
{
LoadoutItemIdsObservable = loadoutItemIdsObservable;
_loadoutItemIdsDisposable = LoadoutItemIdsObservable.OnUI().SubscribeWithErrorLogging(changeSet => LoadoutItemIds.ApplyChanges(changeSet));

_modelActivationDisposable = WhenModelActivated(this, static (model, disposables) =>
{
model.InstalledAtObservable.OnUI().Subscribe(date => model.InstalledAt.Value = date).AddTo(disposables);

if (model._loadoutItemIdsDisposable.Disposable is null)
{
model._loadoutItemIdsDisposable.Disposable = model.LoadoutItemIdsObservable.OnUI().SubscribeWithErrorLogging(changeSet => model.LoadoutItemIds.ApplyChanges(changeSet));
}
});
}

Expand Down
3 changes: 1 addition & 2 deletions src/NexusMods.App.UI/Pages/LocalFileDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,10 @@ public IObservable<IChangeSet<LoadoutItemModel, EntityId>> ObserveNestedLoadoutI
return isEnabled.HasValue ? isEnabled.Value : null;
}).DistinctUntilChanged(x => x is null ? -1 : x.Value ? 1 : 0);

LoadoutItemModel model = new FakeParentLoadoutItemModel
LoadoutItemModel model = new FakeParentLoadoutItemModel(loadoutItemIdsObservable)
{
NameObservable = Observable.Return(libraryFile.AsLibraryItem().Name),
InstalledAtObservable = installedAtObservable,
LoadoutItemIdsObservable = loadoutItemIdsObservable,
IsEnabledObservable = isEnabledObservable,

HasChildrenObservable = Observable.Return(true),
Expand Down
3 changes: 1 addition & 2 deletions src/NexusMods.App.UI/Pages/NexusModsDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,10 @@ public IObservable<IChangeSet<LoadoutItemModel, EntityId>> ObserveNestedLoadoutI
return isEnabled.HasValue ? isEnabled.Value : null;
}).DistinctUntilChanged(x => x is null ? -1 : x.Value ? 1 : 0);

LoadoutItemModel model = new FakeParentLoadoutItemModel
LoadoutItemModel model = new FakeParentLoadoutItemModel(loadoutItemIdsObservable)
{
NameObservable = Observable.Return(modPage.Name),
InstalledAtObservable = installedAtObservable,
LoadoutItemIdsObservable = loadoutItemIdsObservable,
IsEnabledObservable = isEnabledObservable,

HasChildrenObservable = hasChildrenObservable,
Expand Down
Loading