diff --git a/src/Networking/NexusMods.Networking.NexusWebApi/ModUpdateService.cs b/src/Networking/NexusMods.Networking.NexusWebApi/ModUpdateService.cs index 7749d830c1..6d863bcd75 100644 --- a/src/Networking/NexusMods.Networking.NexusWebApi/ModUpdateService.cs +++ b/src/Networking/NexusMods.Networking.NexusWebApi/ModUpdateService.cs @@ -400,7 +400,12 @@ public readonly record struct ModUpdatesOnModPage(ModUpdateOnPage[] FileMappings /// /// Returns the newest file across mods on this mod page. /// - public NexusModsFileMetadata.ReadOnly NewestFile() + public NexusModsFileMetadata.ReadOnly NewestFile() => MappingWithNewestFile().NewestFile; + + /// + /// Returns the instance with the newest file. + /// + 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. @@ -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; } /// diff --git a/src/NexusMods.App.UI/Pages/NexusModsDataProvider.cs b/src/NexusMods.App.UI/Pages/NexusModsDataProvider.cs index 9318ff3aa0..372b9b8999 100644 --- a/src/NexusMods.App.UI/Pages/NexusModsDataProvider.cs +++ b/src/NexusMods.App.UI/Pages/NexusModsDataProvider.cs @@ -115,8 +115,11 @@ private CompositeItemModel 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(); @@ -126,7 +129,7 @@ private CompositeItemModel ToLibraryItemModel(NexusModsModPageMetadata componentFactory: (valueObservable, initialValue) => new LibraryComponents.NewVersionAvailable( currentVersion: new StringComponent( initialValue: string.Empty, - valueObservable: currentVersionObservable + valueObservable: currentUpdateVersionObservable ), newVersion: initialValue, newVersionObservable: valueObservable