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 off-screen row updates in the Library #2146

Merged
merged 5 commits into from
Oct 9, 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 @@ -10,29 +10,29 @@ namespace NexusMods.Abstractions.MnemonicDB.Attributes.Extensions;
/// </summary>
public static class EntityExtensions
{

/// <summary>
/// Gets the largest transaction id in the model.
/// </summary>
public static TxId MostRecentTxId(this IReadOnlyModel model)
{
return model.Max(m => m.T);
}



/// <summary>
/// Gets the timestamp of the transaction that created the model.
/// </summary>
/// <param name="model"></param>
/// <param name="dateTime">A default value to return if the model doesn't exist.</param>
/// <returns></returns>
public static DateTime GetCreatedAt<T>(this T model)
public static DateTime GetCreatedAt<T>(this T model, DateTime? dateTime = null)
where T : IReadOnlyModel
{
if (model.Count == 0)
return dateTime ?? DateTime.MinValue;
var tx = new Transaction.ReadOnly(model.Db, EntityId.From(model.Min(m => m.T).Value));
return Transaction.Timestamp.Get(tx);
}


/// <summary>
/// Tries to parse an entity id from a hex string.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected TreeDataGridAdapter()
.AddTo(disposables);

self.Roots
.ObserveCountChanged()
.ObserveCountChanged(notifyCurrentCount: true)
.Subscribe(self, static (count, self) => self.IsSourceEmpty.Value = count == 0)
.AddTo(disposables);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public FakeParentLibraryItemModel(LibraryItemId libraryItemId, IObservable<IChan
model.NumInstalledObservable
.ToObservable()
.CombineLatest(
source2: model.LibraryItems.ObserveCountChanged(),
source2: model.LibraryItems.ObserveCountChanged(notifyCurrentCount: true),
source3: model.WhenAnyValue(static model => model.IsExpanded).ToObservable(),
source4: model.IsInstalledInLoadout,
static (a,b,c , _) => (a,b,c)
Expand Down
40 changes: 24 additions & 16 deletions src/NexusMods.App.UI/Pages/LibraryPage/LibraryItemModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public LibraryItemModel(LibraryItemId libraryItemId)

_modelActivationDisposable = WhenModelActivated(this, static (model, disposables) =>
{

Debug.Assert(model.Ticker is not null, "should've been set before activation");
model.Ticker.Subscribe(model, static (now, model) =>
{
Expand All @@ -62,31 +63,38 @@ public LibraryItemModel(LibraryItemId libraryItemId)
}).AddTo(disposables);

model.LinkedLoadoutItems
.ObserveCountChanged()
// Observe Count Changed defaults to not notifying the current count on a new subscription
// Because this chain will be destroyed when the model is deactivated, we want to know the current count
// when we reactivate a gain. Rows in a TreeDataGrid are virtualized and so they will be repeatedly activated and deactivated
.ObserveCountChanged(notifyCurrentCount: true)
.Subscribe(model, static (count, model) =>
{
if (count > 0)
{
model.InstallText.Value = "Installed";
model.IsInstalledInLoadout.Value = true;
model.InstalledDate.Value = model.LinkedLoadoutItems.Select(static kv => kv.Value.GetCreatedAt()).Max();
model.FormattedInstalledDate.Value = FormatDate(DateTime.Now, model.InstalledDate.Value);
if (count > 0)
{
model.InstallText.Value = "Installed";
model.IsInstalledInLoadout.Value = true;
model.InstalledDate.Value = model.LinkedLoadoutItems.Select(static kv => kv.Value.GetCreatedAt()).Max();
model.FormattedInstalledDate.Value = FormatDate(DateTime.Now, model.InstalledDate.Value);
}
else
{
model.InstallText.Value = "Install";
model.IsInstalledInLoadout.Value = false;
model.InstalledDate.Value = DateTime.UnixEpoch;
model.FormattedInstalledDate.Value = "-";
}
}
else
{
model.InstallText.Value = "Install";
model.IsInstalledInLoadout.Value = false;
model.InstalledDate.Value = DateTime.UnixEpoch;
model.FormattedInstalledDate.Value = "-";
}
}).AddTo(disposables);
)
.AddTo(disposables);

model.FormattedCreatedAtDate.Value = FormatDate(DateTime.Now, model.CreatedAtDate.Value);
model.FormattedInstalledDate.Value = FormatDate(DateTime.Now, model.InstalledDate.Value);

if (model._linkedLoadoutItemsDisposable.Disposable is null)
{
model._linkedLoadoutItemsDisposable.Disposable = model.LinkedLoadoutItemsObservable.OnUI().SubscribeWithErrorLogging(changeSet => model.LinkedLoadoutItems.ApplyChanges(changeSet));
model._linkedLoadoutItemsDisposable.Disposable = model.LinkedLoadoutItemsObservable
.OnUI()
.SubscribeWithErrorLogging(changeSet => model.LinkedLoadoutItems.ApplyChanges(changeSet));
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/NexusMods.App.UI/Pages/LoadoutPage/LoadoutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public LoadoutViewModel(IWindowManager windowManager, IServiceProvider servicePr
configureAwait: false).AddTo(disposables);

// Compute the target group for the ViewFilesCommand
Adapter.SelectedModels.ObserveCountChanged()
Adapter.SelectedModels.ObserveCountChanged(notifyCurrentCount: true)
.Select(this, static (count, vm) => count == 1 ? vm.Adapter.SelectedModels.First() : null)
.ObserveOnThreadPool()
.Select(_connection,
Expand Down
1 change: 1 addition & 0 deletions src/NexusMods.Collections/NexusMods.Collections.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<ItemGroup>
<ProjectReference Include="..\Abstractions\NexusMods.Abstractions.Collections\NexusMods.Abstractions.Collections.csproj" />
<ProjectReference Include="..\Abstractions\NexusMods.Abstractions.FileExtractor\NexusMods.Abstractions.FileExtractor.csproj" />
<ProjectReference Include="..\Abstractions\NexusMods.Abstractions.Jobs\NexusMods.Abstractions.Jobs.csproj" />
<ProjectReference Include="..\Abstractions\NexusMods.Abstractions.Library\NexusMods.Abstractions.Library.csproj" />
<ProjectReference Include="..\ArchiveManagement\NexusMods.FileExtractor\NexusMods.FileExtractor.csproj" />
Expand Down
Loading