Refactor weapon data
This commit is contained in:
@@ -293,7 +293,7 @@ export async function getStaticProps({
|
||||
},
|
||||
{ weaponIds: [], stigmataIds: [] }
|
||||
)
|
||||
const weaponMap = getWeaponMapByIds(weaponIds)
|
||||
const weaponMap = getWeaponMapByIds(weaponIds, locale)
|
||||
|
||||
const stigmataMap = getStigmataMapByIds(stigmataIds)
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ export default BattlesuitListPage
|
||||
export async function getStaticProps({ locale }: NextPageContext) {
|
||||
return {
|
||||
props: {
|
||||
battlesuits: listBattlesuits().map((battlesuit) => {
|
||||
battlesuits: listBattlesuits(locale).map((battlesuit) => {
|
||||
return {
|
||||
id: battlesuit.id,
|
||||
name: battlesuit.name,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { Box, Card, Heading, Paragraph } from '@theme-ui/components'
|
||||
import { NextPageContext } from 'next'
|
||||
import SquareImageBox from '../../../../components/atoms/SquareImageBox'
|
||||
import Breadcrumb from '../../../../components/organisms/Breadcrumb'
|
||||
import { WeaponData } from '../../../../lib/honkai3rd/weapons'
|
||||
import { generateI18NPaths, getI18NProps } from '../../../../server/i18n'
|
||||
import {
|
||||
@@ -9,8 +10,7 @@ import {
|
||||
getWeaponMapByIds,
|
||||
listWeapons,
|
||||
} from '../../../../server/data/honkai3rd/weapons'
|
||||
import { useRouter } from 'next/router'
|
||||
import { useTranslation, translate } from '../../../../lib/i18n'
|
||||
import { useTranslation } from '../../../../lib/i18n'
|
||||
import PageLink from '../../../../components/atoms/PageLink'
|
||||
import { assetsBucketBaseUrl } from '../../../../lib/consts'
|
||||
import { getBattlesuitMapByIds } from '../../../../server/data/honkai3rd/battlesuits'
|
||||
@@ -29,20 +29,29 @@ const WeaponShowPage = ({
|
||||
battlesuitMap,
|
||||
weaponMap,
|
||||
}: WeaponShowPageProps) => {
|
||||
const { locale } = useRouter()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const weaponName = translate(locale, { 'ko-KR': weapon.krName }, weapon.name)
|
||||
const weaponCategory = t(`weapons-show.${weapon.category}`)
|
||||
|
||||
return (
|
||||
<Box p={3}>
|
||||
<Heading as='h1'>{weaponName}</Heading>
|
||||
<Breadcrumb
|
||||
items={[
|
||||
{ href: '/honkai3rd', label: t('common.honkai-3rd') },
|
||||
{ href: '/honkai3rd/weapons', label: t('common.weapons') },
|
||||
{
|
||||
href: `/honkai3rd/weapons/${weapon.id}`,
|
||||
label: weapon.name,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
<Heading as='h1'>{weapon.name}</Heading>
|
||||
|
||||
<Box mb={3}>
|
||||
<SquareImageBox
|
||||
size={100}
|
||||
alt={weaponName}
|
||||
alt={weapon.name}
|
||||
src={`${assetsBucketBaseUrl}/honkai3rd/weapons/${weapon.id}.png`}
|
||||
/>
|
||||
</Box>
|
||||
@@ -115,7 +124,7 @@ const WeaponShowPage = ({
|
||||
return (
|
||||
<Card key={skill.name} mb={3}>
|
||||
<Heading as='h3' p={2} m={0} sx={{ borderBottom: 'default' }}>
|
||||
{translate(locale, { 'ko-KR': skill.krName }, skill.name)}
|
||||
{skill.name}
|
||||
</Heading>
|
||||
<Paragraph
|
||||
p={2}
|
||||
@@ -123,11 +132,7 @@ const WeaponShowPage = ({
|
||||
whiteSpace: 'pre-wrap',
|
||||
}}
|
||||
>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': skill.krDescription },
|
||||
skill.description
|
||||
)}
|
||||
{skill.description}
|
||||
</Paragraph>
|
||||
</Card>
|
||||
)
|
||||
@@ -143,7 +148,7 @@ export async function getStaticProps({
|
||||
params,
|
||||
locale,
|
||||
}: NextPageContext & { params: { weaponId: string } }) {
|
||||
const weapon = getWeaponById(params.weaponId)
|
||||
const weapon = getWeaponById(params.weaponId, locale)
|
||||
const battlesuitMap = getBattlesuitMapByIds(
|
||||
weapon != null && weapon.battlesuits != null
|
||||
? weapon.battlesuits.map(({ id }) => id)
|
||||
@@ -160,7 +165,7 @@ export async function getStaticProps({
|
||||
weaponIds.push(...weapon.originalWeapons)
|
||||
}
|
||||
}
|
||||
const weaponMap = getWeaponMapByIds(weaponIds)
|
||||
const weaponMap = getWeaponMapByIds(weaponIds, locale)
|
||||
|
||||
return {
|
||||
props: {
|
||||
|
||||
@@ -61,7 +61,7 @@ const VersionShowPage = ({
|
||||
})
|
||||
.join(',')} / ${t('versions.new-weapons')}: ${weapons
|
||||
.map((weapon) => {
|
||||
return translate(locale, { 'ko-KR': weapon.krName }, weapon.name)
|
||||
return weapon.name
|
||||
})
|
||||
.join(',')}`}
|
||||
/>
|
||||
@@ -136,11 +136,6 @@ const VersionShowPage = ({
|
||||
</Heading>
|
||||
<Box mb={3} sx={{ display: 'inline-block' }}>
|
||||
{weapons.map((weapon) => {
|
||||
const weaponName = translate(
|
||||
locale,
|
||||
{ 'ko-KR': weapon.krName },
|
||||
weapon.name
|
||||
)
|
||||
return (
|
||||
<NextLink
|
||||
key={weapon.id}
|
||||
@@ -152,10 +147,10 @@ const VersionShowPage = ({
|
||||
<SquareImageBox
|
||||
size={40}
|
||||
src={`${assetsBucketBaseUrl}/honkai3rd/weapons/${weapon.id}.png`}
|
||||
alt={`${weaponName}`}
|
||||
alt={`${weapon.name}`}
|
||||
mr={2}
|
||||
/>
|
||||
<Text>{weaponName}</Text>
|
||||
<Text>{weapon.name}</Text>
|
||||
</Flex>
|
||||
</Link>
|
||||
</NextLink>
|
||||
|
||||
@@ -130,11 +130,6 @@ const VersionIndexPage = ({
|
||||
</Heading>
|
||||
<Box mb={3} sx={{ display: 'inline-block' }}>
|
||||
{currentVersionNewWeapons.map((weapon) => {
|
||||
const weaponName = translate(
|
||||
locale,
|
||||
{ 'ko-KR': weapon.krName },
|
||||
weapon.name
|
||||
)
|
||||
return (
|
||||
<NextLink
|
||||
key={weapon.id}
|
||||
@@ -146,10 +141,10 @@ const VersionIndexPage = ({
|
||||
<SquareImageBox
|
||||
size={40}
|
||||
src={`${assetsBucketBaseUrl}/honkai3rd/weapons/${weapon.id}.png`}
|
||||
alt={`${weaponName}`}
|
||||
alt={`${weapon.name}`}
|
||||
mr={2}
|
||||
/>
|
||||
<Text>{weaponName}</Text>
|
||||
<Text>{weapon.name}</Text>
|
||||
</Flex>
|
||||
</Link>
|
||||
</NextLink>
|
||||
|
||||
@@ -10,8 +10,7 @@ import {
|
||||
getWeaponMapByIds,
|
||||
listWeapons,
|
||||
} from '../../../server/data/honkai3rd/weapons'
|
||||
import { useRouter } from 'next/router'
|
||||
import { useTranslation, translate } from '../../../lib/i18n'
|
||||
import { useTranslation } from '../../../lib/i18n'
|
||||
import Head from '../../../components/atoms/Head'
|
||||
import PageLink from '../../../components/atoms/PageLink'
|
||||
import { assetsBucketBaseUrl } from '../../../lib/consts'
|
||||
@@ -20,7 +19,6 @@ import { getBattlesuitMapByIds } from '../../../server/data/honkai3rd/battlesuit
|
||||
import { BattlesuitData } from '../../../lib/honkai3rd/battlesuits'
|
||||
import BattlesuitCard from '../../../components/molecules/BattlesuitCard'
|
||||
import WeaponCard from '../../../components/molecules/WeaponCard'
|
||||
// import SourceCard from '../../../components/molecules/SourceCard'
|
||||
|
||||
interface WeaponShowPageProps {
|
||||
weapon: WeaponData
|
||||
@@ -33,16 +31,14 @@ const WeaponShowPage = ({
|
||||
battlesuitMap,
|
||||
weaponMap,
|
||||
}: WeaponShowPageProps) => {
|
||||
const { locale } = useRouter()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const weaponName = translate(locale, { 'ko-KR': weapon.krName }, weapon.name)
|
||||
const weaponCategory = t(`weapons-show.${weapon.category}`)
|
||||
|
||||
return (
|
||||
<Honkai3rdLayout>
|
||||
<Head
|
||||
title={`${weaponName} - ${t('common.honkai-3rd')} - ${t(
|
||||
title={`${weapon.name} - ${t('common.honkai-3rd')} - ${t(
|
||||
'common.abyss-lab'
|
||||
)}`}
|
||||
description={`${t('common.honkai-3rd')} ${t(
|
||||
@@ -59,17 +55,17 @@ const WeaponShowPage = ({
|
||||
{ href: '/honkai3rd/weapons', label: t('common.weapons') },
|
||||
{
|
||||
href: `/honkai3rd/weapons/${weapon.id}`,
|
||||
label: weaponName,
|
||||
label: weapon.name,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
<Heading as='h1'>{weaponName}</Heading>
|
||||
<Heading as='h1'>{weapon.name}</Heading>
|
||||
|
||||
<Box mb={3}>
|
||||
<SquareImageBox
|
||||
size={100}
|
||||
alt={weaponName}
|
||||
alt={weapon.name}
|
||||
src={`${assetsBucketBaseUrl}/honkai3rd/weapons/${weapon.id}.png`}
|
||||
/>
|
||||
</Box>
|
||||
@@ -142,7 +138,7 @@ const WeaponShowPage = ({
|
||||
return (
|
||||
<Card key={skill.name} mb={3}>
|
||||
<Heading as='h3' p={2} m={0} sx={{ borderBottom: 'default' }}>
|
||||
{translate(locale, { 'ko-KR': skill.krName }, skill.name)}
|
||||
{skill.name}
|
||||
</Heading>
|
||||
<Paragraph
|
||||
p={2}
|
||||
@@ -150,11 +146,7 @@ const WeaponShowPage = ({
|
||||
whiteSpace: 'pre-wrap',
|
||||
}}
|
||||
>
|
||||
{translate(
|
||||
locale,
|
||||
{ 'ko-KR': skill.krDescription },
|
||||
skill.description
|
||||
)}
|
||||
{skill.description}
|
||||
</Paragraph>
|
||||
</Card>
|
||||
)
|
||||
@@ -171,11 +163,12 @@ export async function getStaticProps({
|
||||
params,
|
||||
locale,
|
||||
}: NextPageContext & { params: { weaponId: string } }) {
|
||||
const weapon = getWeaponById(params.weaponId)
|
||||
const weapon = getWeaponById(params.weaponId, locale)
|
||||
const battlesuitMap = getBattlesuitMapByIds(
|
||||
weapon != null && weapon.battlesuits != null
|
||||
? weapon.battlesuits.map(({ id }) => id)
|
||||
: []
|
||||
: [],
|
||||
locale
|
||||
)
|
||||
|
||||
const weaponIds = []
|
||||
@@ -187,7 +180,7 @@ export async function getStaticProps({
|
||||
weaponIds.push(...weapon.originalWeapons)
|
||||
}
|
||||
}
|
||||
const weaponMap = getWeaponMapByIds(weaponIds)
|
||||
const weaponMap = getWeaponMapByIds(weaponIds, locale)
|
||||
|
||||
return {
|
||||
props: {
|
||||
|
||||
@@ -16,7 +16,7 @@ import Honkai3rdLayout from '../../../components/layouts/Honkai3rdLayout'
|
||||
|
||||
type WeaponListItemData = Pick<
|
||||
WeaponData,
|
||||
'id' | 'name' | 'rarity' | 'category' | 'krName'
|
||||
'id' | 'name' | 'rarity' | 'category'
|
||||
>
|
||||
|
||||
interface WeaponListPageProps {
|
||||
@@ -110,8 +110,8 @@ export default WeaponListPage
|
||||
export async function getStaticProps({ locale }: NextPageContext) {
|
||||
return {
|
||||
props: {
|
||||
weaponDataList: listWeapons().map((weapon) => {
|
||||
return pick(['name', 'id', 'rarity', 'category', 'krName'], weapon)
|
||||
weaponDataList: listWeapons(locale).map((weapon) => {
|
||||
return pick(['name', 'id', 'rarity', 'category'], weapon)
|
||||
}),
|
||||
...(await getI18NProps(locale)),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user