Refactor battlesuits.show page static prop generation
This commit is contained in:
@@ -36,11 +36,11 @@ import { capitalize } from '../../../lib/string'
|
|||||||
import { assetsBucketBaseUrl } from '../../../lib/consts'
|
import { assetsBucketBaseUrl } from '../../../lib/consts'
|
||||||
import Honkai3rdLayout from '../../../components/layouts/Honkai3rdLayout'
|
import Honkai3rdLayout from '../../../components/layouts/Honkai3rdLayout'
|
||||||
import { WeaponData } from '../../../lib/honkai3rd/weapons'
|
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 { StigmataData } from '../../../lib/honkai3rd/stigmata'
|
||||||
import WeaponCard from '../../../components/molecules/WeaponCard'
|
import WeaponCard from '../../../components/molecules/WeaponCard'
|
||||||
import StigmataCard from '../../../components/molecules/StigmataCard'
|
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 WeaponObjectMap = { [key: string]: WeaponData }
|
||||||
type StigmataObjectMap = { [key: string]: StigmataData }
|
type StigmataObjectMap = { [key: string]: StigmataData }
|
||||||
@@ -206,16 +206,24 @@ const BattlesuitShowPage = ({
|
|||||||
{t(`battlesuit-show.equipmentTypes.${equipmentItem.type}`)}
|
{t(`battlesuit-show.equipmentTypes.${equipmentItem.type}`)}
|
||||||
</Heading>
|
</Heading>
|
||||||
<Flex>
|
<Flex>
|
||||||
<WeaponCard weapon={weaponMap[equipmentItem.weapon]} />
|
{equipmentItem.weapon != null && (
|
||||||
<StigmataCard
|
<WeaponCard weapon={weaponMap[equipmentItem.weapon]} />
|
||||||
stigmata={stigmataMap[equipmentItem.stigmataTop]}
|
)}
|
||||||
/>
|
{equipmentItem.stigmataTop != null && (
|
||||||
<StigmataCard
|
<StigmataCard
|
||||||
stigmata={stigmataMap[equipmentItem.stigmataMid]}
|
stigmata={stigmataMap[equipmentItem.stigmataTop]}
|
||||||
/>
|
/>
|
||||||
<StigmataCard
|
)}
|
||||||
stigmata={stigmataMap[equipmentItem.stigmataBot]}
|
{equipmentItem.stigmataMid != null && (
|
||||||
/>
|
<StigmataCard
|
||||||
|
stigmata={stigmataMap[equipmentItem.stigmataMid]}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{equipmentItem.stigmataBot != null && (
|
||||||
|
<StigmataCard
|
||||||
|
stigmata={stigmataMap[equipmentItem.stigmataBot]}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Flex>
|
</Flex>
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
@@ -293,26 +301,9 @@ export async function getStaticProps({
|
|||||||
},
|
},
|
||||||
{ weaponIds: [], stigmataIds: [] }
|
{ weaponIds: [], stigmataIds: [] }
|
||||||
)
|
)
|
||||||
const weaponMap = weaponIds.reduce<{ [key: string]: WeaponData }>(
|
const weaponMap = getWeaponMapByIds(weaponIds)
|
||||||
(map, id) => {
|
|
||||||
const weapon = getWeaponById(id)
|
const stigmataMap = getStigmataMapByIds(stigmataIds)
|
||||||
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
|
|
||||||
},
|
|
||||||
{}
|
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
|
|||||||
@@ -55,6 +55,16 @@ export function getBattlesuitById(id: string) {
|
|||||||
return battlesuitMap.get(id)
|
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) {
|
function parseSkillData(rawData: string) {
|
||||||
const [
|
const [
|
||||||
nameSection,
|
nameSection,
|
||||||
|
|||||||
@@ -130,6 +130,16 @@ export function getStigmataSetBySetId(setId: string) {
|
|||||||
return stigmataSetMap.get(setId)
|
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) {
|
function parseStigmataData(rawData: string) {
|
||||||
const [name, skillName, skillDescription] = rawData
|
const [name, skillName, skillDescription] = rawData
|
||||||
.replace(/\\\*/g, '*')
|
.replace(/\\\*/g, '*')
|
||||||
|
|||||||
@@ -56,6 +56,16 @@ export function getWeaponById(id: string) {
|
|||||||
return weaponMap.get(id)
|
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) {
|
function parseWeaponData(rawData: string) {
|
||||||
const [name, ...skillSections] = rawData
|
const [name, ...skillSections] = rawData
|
||||||
.replace(/\\\*/g, '*')
|
.replace(/\\\*/g, '*')
|
||||||
|
|||||||
Reference in New Issue
Block a user