Recover stale latest battle ids
This commit is contained in:
@@ -816,6 +816,7 @@ function normalizeCampaignState(state: Partial<CampaignState>): CampaignState {
|
||||
normalized.sortieItemAssignments = normalizeSortieItemAssignments(recordOrEmpty(normalized.sortieItemAssignments));
|
||||
normalized.reserveTrainingFocus = normalizeReserveTrainingFocusId(normalized.reserveTrainingFocus);
|
||||
normalized.battleHistory = normalizeBattleHistory(normalized.battleHistory);
|
||||
normalized.latestBattleId = normalizeLatestBattleId(normalized.latestBattleId, normalized.battleHistory);
|
||||
normalized.firstBattleReport = normalizeFirstBattleReport(normalized.firstBattleReport);
|
||||
return normalized;
|
||||
}
|
||||
@@ -863,6 +864,15 @@ function normalizeBattleHistory(value: unknown) {
|
||||
}, {});
|
||||
}
|
||||
|
||||
function normalizeLatestBattleId(value: unknown, battleHistory: Record<string, CampaignBattleSettlement>) {
|
||||
if (typeof value === 'string' && value in battleHistory) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return Object.values(battleHistory)
|
||||
.sort((a, b) => String(b.completedAt).localeCompare(String(a.completedAt)))[0]?.battleId;
|
||||
}
|
||||
|
||||
function normalizeCampaignBattleSettlement(value: unknown): CampaignBattleSettlement | undefined {
|
||||
if (!isPlainObject(value)) {
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user