Refactor stigmata data

This commit is contained in:
Sakura Knoll
2022-07-04 12:14:32 +09:00 Unverified
parent f91d61dd93
commit 91b45512ee
13 changed files with 187 additions and 460 deletions
@@ -295,7 +295,7 @@ export async function getStaticProps({
)
const weaponMap = getWeaponMapByIds(weaponIds, locale)
const stigmataMap = getStigmataMapByIds(stigmataIds)
const stigmataMap = getStigmataMapByIds(stigmataIds, locale)
return {
props: {
@@ -229,9 +229,9 @@ export async function getStaticProps({
},
{ weaponIds: [], stigmataIds: [] }
)
const weaponMap = getWeaponMapByIds(weaponIds)
const weaponMap = getWeaponMapByIds(weaponIds, locale)
const stigmataMap = getStigmataMapByIds(stigmataIds)
const stigmataMap = getStigmataMapByIds(stigmataIds, locale)
return {
props: {
@@ -6,47 +6,35 @@ import { StigmataSetProps } from '../../../../components/pages/StigmataSetPage'
import { generateI18NPaths, getI18NProps } from '../../../../server/i18n'
import {
listStigmata,
getStigmataById,
getStigmataListBySetId,
getStigmataSetBySetId,
listStigmataSet,
getStigmaById,
} from '../../../../server/data/honkai3rd/stigmata'
import { Box, Card, Flex, Heading, Paragraph } from 'theme-ui'
import SecondaryLabel from '../../../../components/atoms/SecondaryLabel'
import StigmataCard from '../../../../components/molecules/StigmataCard'
import { translate, useTranslation } from '../../../../lib/i18n'
import { useRouter } from 'next/router'
import { useTranslation } from '../../../../lib/i18n'
import { SingleStigmataPageProps } from '../../../../components/pages/SingleStigmataPage'
type StigmataShowPageProps = StigmataSetProps | SingleStigmataPageProps
const StigmataListPage = (props: StigmataShowPageProps) => {
const { t } = useTranslation()
const { locale } = useRouter()
if (props.type === 'single') {
return null
}
const { stigmataSet, stigmataSetList } = props
const stigmataSetName = translate(
locale,
{ 'ko-KR': stigmataSet.krName },
stigmataSet.name
)
const stigmataSetAltName = translate(
locale,
{ 'ko-KR': stigmataSet.krAltName },
stigmataSet.altName
)
return (
<Box p={3}>
<Box mb={3}>
<Heading as='h1' mb={0}>
{stigmataSetName}
{stigmataSet.name}
</Heading>
<SecondaryLabel>{stigmataSetAltName}</SecondaryLabel>
<SecondaryLabel>{stigmataSet.altName}</SecondaryLabel>
</Box>
<Card mb={3}>
@@ -68,22 +56,12 @@ const StigmataListPage = (props: StigmataShowPageProps) => {
})}
</Flex>
{stigmataSetList.map((stigmataSetItem) => {
const stigmataName = translate(
locale,
{ 'ko-KR': stigmataSetItem.krName },
stigmataSetItem.name
)
const stigmataSkillDescrpition = translate(
locale,
{ 'ko-KR': stigmataSetItem.skill.krDescription },
stigmataSetItem.skill.description
)
return (
<React.Fragment key={stigmataSetItem.id}>
<Box sx={{ p: 2, borderBottom: 'default' }}>
<Heading as='h2' mb={1}>
<PageLink href={`/honkai3rd/stigmata/${stigmataSetItem.id}`}>
{stigmataName}
{stigmataSetItem.name}
</PageLink>
</Heading>
<SecondaryLabel>
@@ -102,7 +80,7 @@ const StigmataListPage = (props: StigmataShowPageProps) => {
'&:last-child': { borderBottom: 'none' },
}}
>
{stigmataSkillDescrpition}
{stigmataSetItem.skill.description}
</Paragraph>
</React.Fragment>
)
@@ -111,34 +89,16 @@ const StigmataListPage = (props: StigmataShowPageProps) => {
<Card>
<Heading as='h2' m={0} p={2} sx={{ borderBottom: 'default' }}>
{translate(
locale,
{ 'ko-KR': stigmataSet.twoSetSkill.krName },
stigmataSet.twoSetSkill.name
)}
{stigmataSet.twoSetSkill.name}
</Heading>
<Paragraph m={0} p={2} sx={{ borderBottom: 'default' }}>
{translate(
locale,
{ 'ko-KR': stigmataSet.twoSetSkill.krDescription },
stigmataSet.twoSetSkill.description
)}
{stigmataSet.twoSetSkill.description}
</Paragraph>
<Heading as='h2' m={0} p={2} sx={{ borderBottom: 'default' }}>
{translate(
locale,
{
'ko-KR': stigmataSet.threeSetSkill.krName,
},
stigmataSet.threeSetSkill.name
)}
{stigmataSet.threeSetSkill.name}
</Heading>
<Paragraph m={0} p={2}>
{translate(
locale,
{ 'ko-KR': stigmataSet.threeSetSkill.krDescription },
stigmataSet.threeSetSkill.description
)}
{stigmataSet.threeSetSkill.description}
</Paragraph>
</Card>
</Box>
@@ -151,29 +111,29 @@ export async function getStaticProps({
params,
locale,
}: NextPageContext & { params: { stigmataId: string } }) {
const stigmataData = getStigmataById(params.stigmataId)!
const stigmataData = getStigmaById(params.stigmataId, locale)!
if (stigmataData != null) {
return {
props: {
type: 'single',
stigmataData: stigmataData,
stigmataSetList: (getStigmataListBySetId(stigmataData.set!) || []).sort(
(a, b) => -a.type.localeCompare(b.type)
),
stigmataSet: getStigmataSetBySetId(stigmataData.set!) || null,
stigmataSetList: (
getStigmataListBySetId(stigmataData.set!, locale) || []
).sort((a, b) => -a.type.localeCompare(b.type)),
stigmataSet: getStigmataSetBySetId(stigmataData.set!, locale) || null,
...(await getI18NProps(locale)),
},
}
}
const [stigmataSetId] = params.stigmataId.split('-set')
const stigmataSet = getStigmataSetBySetId(stigmataSetId)!
const stigmataSet = getStigmataSetBySetId(stigmataSetId, locale)!
return {
props: {
type: 'set',
stigmataSet,
stigmataSetList: (getStigmataListBySetId(stigmataSet.id) || []).sort(
(a, b) => -a.type.localeCompare(b.type)
),
stigmataSetList: (
getStigmataListBySetId(stigmataSet.id, locale) || []
).sort((a, b) => -a.type.localeCompare(b.type)),
...(await getI18NProps(locale)),
},
}
+10 -10
View File
@@ -9,7 +9,7 @@ import StigmataSetPage, {
import { generateI18NPaths, getI18NProps } from '../../../server/i18n'
import {
listStigmata,
getStigmataById,
getStigmaById,
getStigmataListBySetId,
getStigmataSetBySetId,
listStigmataSet,
@@ -31,29 +31,29 @@ export async function getStaticProps({
params,
locale,
}: NextPageContext & { params: { stigmataId: string } }) {
const stigmataData = getStigmataById(params.stigmataId)!
const stigmataData = getStigmaById(params.stigmataId, locale)!
if (stigmataData != null) {
return {
props: {
type: 'single',
stigmataData: stigmataData,
stigmataSetList: (getStigmataListBySetId(stigmataData.set!) || []).sort(
(a, b) => -a.type.localeCompare(b.type)
),
stigmataSet: getStigmataSetBySetId(stigmataData.set!) || null,
stigmataSetList: (
getStigmataListBySetId(stigmataData.set!, locale) || []
).sort((a, b) => -a.type.localeCompare(b.type)),
stigmataSet: getStigmataSetBySetId(stigmataData.set!, locale) || null,
...(await getI18NProps(locale)),
},
}
}
const [stigmataSetId] = params.stigmataId.split('-set')
const stigmataSet = getStigmataSetBySetId(stigmataSetId)!
const stigmataSet = getStigmataSetBySetId(stigmataSetId, locale)!
return {
props: {
type: 'set',
stigmataSet,
stigmataSetList: (getStigmataListBySetId(stigmataSet.id) || []).sort(
(a, b) => -a.type.localeCompare(b.type)
),
stigmataSetList: (
getStigmataListBySetId(stigmataSet.id, locale) || []
).sort((a, b) => -a.type.localeCompare(b.type)),
...(await getI18NProps(locale)),
},
}
+6 -6
View File
@@ -19,8 +19,8 @@ import Head from '../../../components/atoms/Head'
import Honkai3rdLayout from '../../../components/layouts/Honkai3rdLayout'
interface StigmataListPageProps {
stigmataDataList: Pick<StigmataData, 'id' | 'name' | 'rarity' | 'krName'>[]
stigmataSetList: Pick<StigmataSet, 'id' | 'name' | 'rarity' | 'krName'>[]
stigmataDataList: Pick<StigmataData, 'id' | 'name' | 'rarity'>[]
stigmataSetList: Pick<StigmataSet, 'id' | 'name' | 'rarity'>[]
}
const StigmataListPage = ({
@@ -102,11 +102,11 @@ export default StigmataListPage
export async function getStaticProps({ locale }: NextPageContext) {
return {
props: {
stigmataDataList: listStigmata().map((stigmata) =>
pick(['id', 'name', 'rarity', 'krName'], stigmata)
stigmataDataList: listStigmata(locale).map((stigmata) =>
pick(['id', 'name', 'rarity'], stigmata)
),
stigmataSetList: listStigmataSet().map((stigmataSet) =>
pick(['id', 'name', 'rarity', 'krName'], stigmataSet)
stigmataSetList: listStigmataSet(locale).map((stigmataSet) =>
pick(['id', 'name', 'rarity'], stigmataSet)
),
...(await getI18NProps(locale)),
},