import { MainWindowState } from '../../../../../models/mainwindow/main-window-state' ; import { NavigationState } from '../../../../../models/mainwindow/navigation/navigation-state' ; import { MercenariesPersonalHeroesSortCriteria } from '../../../../../models/mercenaries/personal-heroes-sort-criteria.type' ; import { PreferencesService } from '../../../../preferences.service' ; import { MercenariesPersonalHeroesSortEvent } from '../../events/mercenaries/mercenaries-personal-heroes-sort-event' ; import { Processor } from '../processor' ; export class MercenariesPersonalHeroesSortProcessor implements Processor { constructor ( private readonly prefs ) { } public async process ( event , currentState , history , navigationState ) { const prefs = await this . prefs . getPreferences ( ) ; const existingCriteria = prefs . mercenariesPersonalHeroesSortCriteria ; const existingDirection = existingCriteria . find ( ( crit ) => crit . criteria === event . criteria ) ?. direction ; const newCriteria = [ { criteria : event . criteria , direction : existingDirection === 'desc' ? 'asc' : 'desc' } , ... existingCriteria . filter ( ( crit ) => crit . criteria !== event . criteria ) , ] ; this . prefs . updateMercenariesPersonalHeroesSortCriteria ( newCriteria ) ; return [ null , null ] ; } }