Refactor battlesuits.show page static prop generation

This commit is contained in:
Sakura Knoll
2022-03-20 22:23:46 +09:00 Unverified
parent 82690ca6e0
commit 6478c1c5eb
4 changed files with 53 additions and 32 deletions
@@ -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}`)}
</Heading>
<Flex>
{equipmentItem.weapon != null && (
<WeaponCard weapon={weaponMap[equipmentItem.weapon]} />
)}
{equipmentItem.stigmataTop != null && (
<StigmataCard
stigmata={stigmataMap[equipmentItem.stigmataTop]}
/>
)}
{equipmentItem.stigmataMid != null && (
<StigmataCard
stigmata={stigmataMap[equipmentItem.stigmataMid]}
/>
)}
{equipmentItem.stigmataBot != null && (
<StigmataCard
stigmata={stigmataMap[equipmentItem.stigmataBot]}
/>
)}
</Flex>
</Box>
)
@@ -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: {
+10
View File
@@ -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,
+10
View File
@@ -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, '*')
+10
View File
@@ -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, '*')