diff --git a/src/pages/honkai3rd/battlesuits/[battlesuitId].tsx b/src/pages/honkai3rd/battlesuits/[battlesuitId].tsx index c2372874..91f1d56e 100644 --- a/src/pages/honkai3rd/battlesuits/[battlesuitId].tsx +++ b/src/pages/honkai3rd/battlesuits/[battlesuitId].tsx @@ -36,11 +36,11 @@ import { capitalize } from '../../../lib/string' import { assetsBucketBaseUrl } from '../../../lib/consts' import Honkai3rdLayout from '../../../components/layouts/Honkai3rdLayout' import { WeaponData } from '../../../lib/honkai3rd/weapons' -import { getWeaponById } from '../../../server/data/honkai3rd/weapons' +import { getWeaponMapByIds } from '../../../server/data/honkai3rd/weapons' import { StigmataData } from '../../../lib/honkai3rd/stigmata' import WeaponCard from '../../../components/molecules/WeaponCard' import StigmataCard from '../../../components/molecules/StigmataCard' -import { getStigmataById } from '../../../server/data/honkai3rd/stigmata' +import { getStigmataMapByIds } from '../../../server/data/honkai3rd/stigmata' type WeaponObjectMap = { [key: string]: WeaponData } type StigmataObjectMap = { [key: string]: StigmataData } @@ -206,16 +206,24 @@ const BattlesuitShowPage = ({ {t(`battlesuit-show.equipmentTypes.${equipmentItem.type}`)} - - - - + {equipmentItem.weapon != null && ( + + )} + {equipmentItem.stigmataTop != null && ( + + )} + {equipmentItem.stigmataMid != null && ( + + )} + {equipmentItem.stigmataBot != null && ( + + )} ) @@ -293,26 +301,9 @@ export async function getStaticProps({ }, { weaponIds: [], stigmataIds: [] } ) - const weaponMap = weaponIds.reduce<{ [key: string]: WeaponData }>( - (map, id) => { - const weapon = getWeaponById(id) - if (weapon != null) { - map[id] = weapon - } - return map - }, - {} - ) - const stigmataMap = stigmataIds.reduce<{ [key: string]: StigmataData }>( - (map, id) => { - const stigmata = getStigmataById(id) - if (stigmata != null) { - map[id] = stigmata - } - return map - }, - {} - ) + const weaponMap = getWeaponMapByIds(weaponIds) + + const stigmataMap = getStigmataMapByIds(stigmataIds) return { props: { diff --git a/src/server/data/honkai3rd/battlesuits.ts b/src/server/data/honkai3rd/battlesuits.ts index 21e64759..12bd97da 100644 --- a/src/server/data/honkai3rd/battlesuits.ts +++ b/src/server/data/honkai3rd/battlesuits.ts @@ -55,6 +55,16 @@ export function getBattlesuitById(id: string) { return battlesuitMap.get(id) } +export function getBattlesuitMapByIds(idList: string[]) { + return idList.reduce<{ [key: string]: BattlesuitData }>((map, id) => { + const battlesuit = getBattlesuitById(id) + if (battlesuit != null) { + map[id] = battlesuit + } + return map + }, {}) +} + function parseSkillData(rawData: string) { const [ nameSection, diff --git a/src/server/data/honkai3rd/stigmata.ts b/src/server/data/honkai3rd/stigmata.ts index 61412cc9..4cf87894 100644 --- a/src/server/data/honkai3rd/stigmata.ts +++ b/src/server/data/honkai3rd/stigmata.ts @@ -130,6 +130,16 @@ export function getStigmataSetBySetId(setId: string) { return stigmataSetMap.get(setId) } +export function getStigmataMapByIds(idList: string[]) { + return idList.reduce<{ [key: string]: StigmataData }>((map, id) => { + const stigmata = getStigmataById(id) + if (stigmata != null) { + map[id] = stigmata + } + return map + }, {}) +} + function parseStigmataData(rawData: string) { const [name, skillName, skillDescription] = rawData .replace(/\\\*/g, '*') diff --git a/src/server/data/honkai3rd/weapons.ts b/src/server/data/honkai3rd/weapons.ts index 83004c5c..f709d829 100644 --- a/src/server/data/honkai3rd/weapons.ts +++ b/src/server/data/honkai3rd/weapons.ts @@ -56,6 +56,16 @@ export function getWeaponById(id: string) { return weaponMap.get(id) } +export function getWeaponMapByIds(idList: string[]) { + return idList.reduce<{ [key: string]: WeaponData }>((map, id) => { + const weapon = getWeaponById(id) + if (weapon != null) { + map[id] = weapon + } + return map + }, {}) +} + function parseWeaponData(rawData: string) { const [name, ...skillSections] = rawData .replace(/\\\*/g, '*')