@@ -6,6 +6,7 @@ import { selectors as LanguageSelectors } from '../Languages'
6
6
import * as Content from './content'
7
7
import * as Selected from './selected'
8
8
import * as Ids from './ids'
9
+ import * as types from 'aer-types/types'
9
10
import { createAction , ActionsUnion } from '@martin_hotell/rex-tils'
10
11
import { EXPANSIONS_DB_KEY } from './constants'
11
12
import { getContentWithLanguageFallback } from './content/selectors'
@@ -62,7 +63,7 @@ export const Reducer = reduceReducers(
62
63
( state : State , action : Action ) => {
63
64
switch ( action . type ) {
64
65
case ActionTypes . TOGGLE_ALL : {
65
- const allExpansionsSelected = state . ids . every ( id =>
66
+ const allExpansionsSelected = state . ids . every ( ( id ) =>
66
67
state . selected . includes ( id )
67
68
)
68
69
@@ -105,54 +106,38 @@ const getExpansionIds = (
105
106
106
107
const getExpansionsByIdList = createSelector (
107
108
[ Content . selectors . getContent , getExpansionIds ] ,
108
- ( content , ids ) => ids . map ( id => content . ENG [ id ] )
109
+ ( content , ids ) => ids . map ( ( id ) => content . ENG [ id ] )
109
110
)
110
111
111
112
const getExpansionNamesByIdList = createSelector (
112
113
[ getExpansionsByIdList ] ,
113
- expansions => expansions . map ( e => e . name )
114
+ ( expansions ) => expansions . map ( ( e ) => e . name )
114
115
)
115
116
116
117
const getAllExpansionsSelected = createSelector (
117
118
[ Ids . selectors . getIds , Selected . selectors . getSelected ] ,
118
- ( ids , selectedIds ) => ids . every ( id => selectedIds . includes ( id ) )
119
+ ( ids , selectedIds ) => ids . every ( ( id ) => selectedIds . includes ( id ) )
119
120
)
120
121
121
122
const getHasStandaloneExpansion = createSelector (
122
123
[ Selected . selectors . getSelected , Content . selectors . getContent ] ,
123
124
( selectedIds , content ) =>
124
- selectedIds . some ( id => content . ENG [ id ] . type === 'standalone' )
125
+ selectedIds . some ( ( id ) => content . ENG [ id ] . type === 'standalone' )
125
126
)
126
127
127
128
const getStandaloneExpansionIds = createSelector (
128
129
[ Ids . selectors . getIds , Content . selectors . getContent ] ,
129
- ( ids , content ) => ids . filter ( id => content . ENG [ id ] . type === 'standalone' )
130
+ ( ids , content ) => ids . filter ( ( id ) => content . ENG [ id ] . type === 'standalone' )
130
131
)
131
132
132
133
const getMiniExpansionIds = createSelector (
133
134
[ Ids . selectors . getIds , Content . selectors . getContent ] ,
134
- ( ids , content ) => ids . filter ( id => content . ENG [ id ] . type === 'mini' )
135
+ ( ids , content ) => ids . filter ( ( id ) => content . ENG [ id ] . type === 'mini' )
135
136
)
136
137
137
138
const getPromoIds = createSelector (
138
139
[ Ids . selectors . getIds , Content . selectors . getContent ] ,
139
- ( ids , content ) =>
140
- ids
141
- . filter ( id => content . ENG [ id ] . type === 'promo' )
142
- . sort ( ( a , b ) => {
143
- const promoA = content . ENG [ a ] . name
144
- const promoB = content . ENG [ b ] . name
145
-
146
- if ( promoA < promoB ) {
147
- return - 1
148
- }
149
-
150
- if ( promoA > promoB ) {
151
- return 1
152
- }
153
-
154
- return 0
155
- } )
140
+ ( ids , content ) => ids . filter ( ( id ) => content . ENG [ id ] . type === 'promo' )
156
141
)
157
142
158
143
const getStandaloneExpansions = createSelector (
@@ -161,28 +146,62 @@ const getStandaloneExpansions = createSelector(
161
146
getStandaloneExpansionIds ,
162
147
LanguageSelectors . getLanguagesByExpansion ,
163
148
] ,
164
- ( content , ids , languages ) =>
165
- ids . map ( id => getContentWithLanguageFallback ( languages , content , id ) )
149
+ ( content , ids , languages ) => {
150
+ const expansions = ids . map ( ( id ) =>
151
+ getContentWithLanguageFallback ( languages , content , id )
152
+ )
153
+ return sortExpansions ( expansions )
154
+ }
166
155
)
167
156
const getMiniExpansions = createSelector (
168
157
[
169
158
Content . selectors . getContent ,
170
159
getMiniExpansionIds ,
171
160
LanguageSelectors . getLanguagesByExpansion ,
172
161
] ,
173
- ( content , ids , languages ) =>
174
- ids . map ( id => getContentWithLanguageFallback ( languages , content , id ) )
162
+ ( content , ids , languages ) => {
163
+ const expansions = ids . map ( ( id ) =>
164
+ getContentWithLanguageFallback ( languages , content , id )
165
+ )
166
+ return sortExpansions ( expansions )
167
+ }
175
168
)
176
169
const getPromos = createSelector (
177
170
[
178
171
Content . selectors . getContent ,
179
172
getPromoIds ,
180
173
LanguageSelectors . getLanguagesByExpansion ,
181
174
] ,
182
- ( content , ids , languages ) =>
183
- ids . map ( id => getContentWithLanguageFallback ( languages , content , id ) )
175
+ ( content , ids , languages ) => {
176
+ const expansions = ids . map ( ( id ) =>
177
+ getContentWithLanguageFallback ( languages , content , id )
178
+ )
179
+ return sortExpansions ( expansions )
180
+ }
184
181
)
185
182
183
+ function sortExpansions ( expansions : types . Expansion [ ] ) : types . Expansion [ ] {
184
+ return expansions . sort ( ( e1 , e2 ) => {
185
+ if ( e1 . wave < e2 . wave ) {
186
+ return - 1
187
+ }
188
+
189
+ if ( e1 . wave > e2 . wave ) {
190
+ return 1
191
+ }
192
+
193
+ if ( e1 . name < e2 . name ) {
194
+ return - 1
195
+ }
196
+
197
+ if ( e1 . name > e2 . name ) {
198
+ return 1
199
+ }
200
+
201
+ return 0
202
+ } )
203
+ }
204
+
186
205
export const selectors = {
187
206
selected : Selected . selectors ,
188
207
ids : Ids . selectors ,
0 commit comments