Skip to content

Commit

Permalink
Fixed: When an update is available, old version now shows correct ver…
Browse files Browse the repository at this point in the history
…sion.

fixes #2747
  • Loading branch information
Sewer56 committed Feb 27, 2025
1 parent 494add4 commit c0ac158
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,12 @@ public readonly record struct ModUpdatesOnModPage(ModUpdateOnPage[] FileMappings
/// <summary>
/// Returns the newest file across mods on this mod page.
/// </summary>
public NexusModsFileMetadata.ReadOnly NewestFile()
public NexusModsFileMetadata.ReadOnly NewestFile() => MappingWithNewestFile().NewestFile;

/// <summary>
/// Returns the <see cref="ModUpdateOnPage"/> instance with the newest file.
/// </summary>
public ModUpdateOnPage MappingWithNewestFile()
{
// Note(sewer): This matches the behaviour established in the design for
// the mod update feature. The row should show the details of the newest mod.
Expand All @@ -410,15 +415,20 @@ public NexusModsFileMetadata.ReadOnly NewestFile()

// Compare the newest file in all `FileMappings` and return most recent one
// (without LINQ, avoid alloc, since every mod row will touch this code in UI).
var newestFile = FileMappings[0].NewerFiles[0];
var newestUploadTime = FileMappings[0].NewerFiles[0].UploadedAt;
var newestMapping = FileMappings[0];
for (var x = 1; x < FileMappings.Length; x++)
{
var newerFile = FileMappings[x].NewerFiles[0];
if (newerFile.UploadedAt > newestFile.UploadedAt)
newestFile = newerFile;
var mapping = FileMappings[x];
var uploadTime = mapping.NewerFiles[0].UploadedAt;
if (uploadTime > newestUploadTime)
{
newestUploadTime = uploadTime;
newestMapping = mapping;
}
}

return newestFile;
return newestMapping;
}

/// <summary>
Expand Down
9 changes: 6 additions & 3 deletions src/NexusMods.App.UI/Pages/NexusModsDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,11 @@ private CompositeItemModel<EntityId> ToLibraryItemModel(NexusModsModPageMetadata
));

// Update available
var newestVersionObservable = _modUpdateService
.GetNewestModPageVersionObservable(modPage)
var newestModPageObservable = _modUpdateService.GetNewestModPageVersionObservable(modPage);
var currentUpdateVersionObservable = newestModPageObservable
.Select(static optional => !optional.HasValue ? "" : optional.Value.MappingWithNewestFile().File.Version)
.OnUI();
var newestVersionObservable = newestModPageObservable
.Select(static optional => optional.Convert(static updatesOnPage => updatesOnPage.NewestFile().Version))
.OnUI();

Expand All @@ -126,7 +129,7 @@ private CompositeItemModel<EntityId> ToLibraryItemModel(NexusModsModPageMetadata
componentFactory: (valueObservable, initialValue) => new LibraryComponents.NewVersionAvailable(
currentVersion: new StringComponent(
initialValue: string.Empty,
valueObservable: currentVersionObservable
valueObservable: currentUpdateVersionObservable
),
newVersion: initialValue,
newVersionObservable: valueObservable
Expand Down

0 comments on commit c0ac158

Please sign in to comment.