Skip to content

Commit

Permalink
Merge pull request #118 from 2skydev/dev
Browse files Browse the repository at this point in the history
v0.0.24
  • Loading branch information
2skydev authored Oct 22, 2023
2 parents c208d24 + af09c4d commit a2b085d
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/renderer/src/features/duo/DuoSynergyTable/DuoSynergyTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface DuoSynergyForm extends Omit<GetDuoSynergyListOptions, 'champion

export interface FilteredChampionItem {
id: number
enName: string
normalizedName: string
alias: string[]
}

Expand Down Expand Up @@ -103,17 +103,20 @@ const DuoSynergyTable = ({ className }: DuoSynergyTableProps) => {
useEffect(() => {
const championNameAlias = t('league.championNameAlias', { returnObjects: true })

const query = search.replaceAll(' ', '').toLowerCase()

const filteredChampions =
!championNames || !search.trim().length
!championNames || !query.length
? []
: Object.keys(championNames).reduce<FilteredChampionItem[]>((acc, id) => {
const enName = championNames[id].en
const { en: enName, ko: name } = championNames[id]
const alias = championNameAlias[enName] ?? []
const normalizedName = name.replaceAll(' ', '').toLowerCase()

if (includesByCho(search, enName) || alias.some(x => includesByCho(search, x))) {
if (includesByCho(query, normalizedName) || alias.some(x => includesByCho(query, x))) {
acc.push({
id: +id,
enName,
normalizedName,
alias,
})
}
Expand All @@ -122,12 +125,12 @@ const DuoSynergyTable = ({ className }: DuoSynergyTableProps) => {
}, [])

const distanceChampionNames: string[] = correctByDistance(
search,
filteredChampions.map(x => x.enName),
query,
filteredChampions.map(x => x.normalizedName),
)

const filteredChampionId: number | null = distanceChampionNames.length
? filteredChampions.find(x => x.enName === distanceChampionNames[0])!.id
? filteredChampions.find(x => x.normalizedName === distanceChampionNames[0])!.id
: filteredChampions.length === 1
? filteredChampions[0].id
: null
Expand Down

0 comments on commit a2b085d

Please sign in to comment.