Skip to content

Commit ce9780b

Browse files
committed
Ensure we create the sort order on loadout/collection creation to allow ViewModels to reference it
1 parent 25742a6 commit ce9780b

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/NexusMods.Abstractions.Games/SortOrder/SortOrderManager.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,21 @@ public async ValueTask UpdateLoadOrders(LoadoutId loadoutId, Optional<Collection
4747
await sortOrderVariety.ReconcileSortOrder(sortOrderId, token: token);
4848
}
4949
}
50+
51+
protected async ValueTask CreateSortOrders(LoadoutId loadoutId, Optional<CollectionGroupId> collectionGroupId = default, CancellationToken token = default)
52+
{
53+
var parentEntity = collectionGroupId.HasValue
54+
? OneOf<LoadoutId, CollectionGroupId>.FromT1(collectionGroupId.Value)
55+
: OneOf<LoadoutId, CollectionGroupId>.FromT0(loadoutId);
56+
57+
foreach (var sortOrderVariety in _sortOrderVarieties.Values)
58+
{
59+
// Create the sort order for each variety
60+
_ = await sortOrderVariety.GetOrCreateSortOrderFor(loadoutId, parentEntity, token);
61+
}
62+
}
5063

51-
public async ValueTask DeleteSortOrders(LoadoutId loadoutId, Optional<CollectionGroupId> collectionGroupId = default, CancellationToken token = default)
64+
protected async ValueTask DeleteSortOrders(LoadoutId loadoutId, Optional<CollectionGroupId> collectionGroupId = default, CancellationToken token = default)
5265
{
5366
var parentEntity = collectionGroupId.HasValue
5467
? OneOf<LoadoutId, CollectionGroupId>.FromT1(collectionGroupId.Value)
@@ -107,7 +120,7 @@ protected void SubscribeToChanges(GameId gameId)
107120
case ChangeReason.Add:
108121
// Create the sort order for this loadout
109122
// Might not be needed if the other subscription to loadout items handles it
110-
// await state.UpdateLoadOrders(loadoutId, token: token);
123+
await state.CreateSortOrders(loadoutId, token: token);
111124
break;
112125
case ChangeReason.Update:
113126
// If loadout changes, we handle that in a separate subscription
@@ -141,7 +154,7 @@ protected void SubscribeToChanges(GameId gameId)
141154
case ChangeReason.Add:
142155
// Create the sort order for this collection group
143156
// Might not be needed if the other subscription to loadout items handles it
144-
// await state.UpdateLoadOrders(loadoutId, parentEntity, token: token);
157+
await state.CreateSortOrders(loadoutId, parentEntity, token: token);
145158
break;
146159
case ChangeReason.Update:
147160
// If collection group changes, we handle that in a separate subscription

0 commit comments

Comments
 (0)