Skip to content

Commit

Permalink
FIX: issue expansion names not being translated correctly in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
on3iro committed Jun 2, 2020
1 parent 6cb3170 commit 3d73b23
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
import { ExpansionContentStateSlice } from './types'
import { createSelector } from 'reselect'
import * as Languages from '../../Languages'

import { selectors as LanguageSelectors } from '../../Languages'
import { ContentStruct } from '../../helpers'
import { Expansion } from 'aer-types'

const getContent = (state: ExpansionContentStateSlice) =>
state.Settings.Expansions.Expansions.content

const getId = (_: unknown, props: { expansionId: string }) => props.expansionId

export const getContentWithLanguageFallback = (
languages: Languages.State,
content: ContentStruct<Expansion>,
id: string
) => {
// Just get the corresponding expansion id from the english version
const language = languages[content.ENG[id].id]

return content[language][id] || content.ENG[id]
}

const getExpansionById = createSelector(
[LanguageSelectors.getLanguagesByExpansion, getContent, getId],
(languages, content, id) => {
// Just get the corresponding expansion id from the english version
const language = languages[content.ENG[id].id]

return content[language][id] || content.ENG[id]
}
getContentWithLanguageFallback
)

export const selectors = {
Expand Down
29 changes: 23 additions & 6 deletions src/Redux/Store/Settings/Expansions/Expansions/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { combineReducers, reduceReducers, Cmd, loop } from 'redux-loop'
import { createSelector } from 'reselect'
import { set as setToDb } from 'idb-keyval'
import { selectors as LanguageSelectors } from '../Languages'

import * as Content from './content'
import * as Selected from './selected'
import * as Ids from './ids'
import { createAction, ActionsUnion } from '@martin_hotell/rex-tils'
import { EXPANSIONS_DB_KEY } from './constants'
import { getContentWithLanguageFallback } from './content/selectors'

///////////
// STATE //
Expand Down Expand Up @@ -154,16 +156,31 @@ const getPromoIds = createSelector(
)

const getStandaloneExpansions = createSelector(
[Content.selectors.getContent, getStandaloneExpansionIds],
(content, ids) => ids.map(id => content.ENG[id])
[
Content.selectors.getContent,
getStandaloneExpansionIds,
LanguageSelectors.getLanguagesByExpansion,
],
(content, ids, languages) =>
ids.map(id => getContentWithLanguageFallback(languages, content, id))
)
const getMiniExpansions = createSelector(
[Content.selectors.getContent, getMiniExpansionIds],
(content, ids) => ids.map(id => content.ENG[id])
[
Content.selectors.getContent,
getMiniExpansionIds,
LanguageSelectors.getLanguagesByExpansion,
],
(content, ids, languages) =>
ids.map(id => getContentWithLanguageFallback(languages, content, id))
)
const getPromos = createSelector(
[Content.selectors.getContent, getPromoIds],
(content, ids) => ids.map(id => content.ENG[id])
[
Content.selectors.getContent,
getPromoIds,
LanguageSelectors.getLanguagesByExpansion,
],
(content, ids, languages) =>
ids.map(id => getContentWithLanguageFallback(languages, content, id))
)

export const selectors = {
Expand Down
2 changes: 1 addition & 1 deletion src/Redux/Store/Settings/Expansions/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Entity =
| UpgradedBasicNemesisCard
| ICard

type ContentStruct<T> = {
export type ContentStruct<T> = {
[key in LanguageKey]: {
[id: string]: T
}
Expand Down

0 comments on commit 3d73b23

Please sign in to comment.