From d0323861dbb5bdc4c93f6a845d169c9e384d9542 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 4 Mar 2022 19:20:06 -0800 Subject: [PATCH] Localize and modernize search result components --- components/CharacterResult/index.tsx | 43 ++++++++++++++------------- components/SummonResult/index.tsx | 43 ++++++++++++++------------- components/WeaponResult/index.tsx | 44 +++++++++++++++------------- 3 files changed, 69 insertions(+), 61 deletions(-) diff --git a/components/CharacterResult/index.tsx b/components/CharacterResult/index.tsx index 183ebe55..f2395019 100644 --- a/components/CharacterResult/index.tsx +++ b/components/CharacterResult/index.tsx @@ -1,4 +1,6 @@ import React from 'react' +import { useRouter } from 'next/router' + import UncapIndicator from '~components/UncapIndicator' import WeaponLabelIcon from '~components/WeaponLabelIcon' @@ -11,28 +13,29 @@ interface Props { const Element = ['null', 'wind', 'fire', 'water', 'earth', 'dark', 'light'] -class CharacterResult extends React.Component { - render() { - const character = this.props.data +const CharacterResult = (props: Props) => { + const router = useRouter() + const locale = (router.locale && ['en', 'ja'].includes(router.locale)) ? router.locale : 'en' - return ( -
  • - {character.name.en} -
    -
    {character.name.en}
    - -
    - -
    + const character = props.data + + return( +
  • + {character.name[locale]} +
    +
    {character.name[locale]}
    + +
    +
    -
  • - ) - } + + + ) } export default CharacterResult \ No newline at end of file diff --git a/components/SummonResult/index.tsx b/components/SummonResult/index.tsx index 2df04f44..c5c32990 100644 --- a/components/SummonResult/index.tsx +++ b/components/SummonResult/index.tsx @@ -1,4 +1,6 @@ import React from 'react' +import { useRouter } from 'next/router' + import UncapIndicator from '~components/UncapIndicator' import WeaponLabelIcon from '~components/WeaponLabelIcon' @@ -11,28 +13,29 @@ interface Props { const Element = ['null', 'wind', 'fire', 'water', 'earth', 'dark', 'light'] -class SummonResult extends React.Component { - render() { - const summon = this.props.data +const SummonResult = (props: Props) => { + const router = useRouter() + const locale = (router.locale && ['en', 'ja'].includes(router.locale)) ? router.locale : 'en' - return ( -
  • - {summon.name.en} -
    -
    {summon.name.en}
    - -
    - -
    + const summon = props.data + + return ( +
  • + {summon.name[locale]} +
    +
    {summon.name[locale]}
    + +
    +
    -
  • - ) - } + + + ) } export default SummonResult \ No newline at end of file diff --git a/components/WeaponResult/index.tsx b/components/WeaponResult/index.tsx index 725b924f..66b4332a 100644 --- a/components/WeaponResult/index.tsx +++ b/components/WeaponResult/index.tsx @@ -1,4 +1,6 @@ import React from 'react' +import { useRouter } from 'next/router' + import UncapIndicator from '~components/UncapIndicator' import WeaponLabelIcon from '~components/WeaponLabelIcon' @@ -13,29 +15,29 @@ const Element = ['null', 'wind', 'fire', 'water', 'earth', 'dark', 'light'] const Proficiency = ['none', 'sword', 'dagger', 'axe', 'spear', 'bow', 'staff', 'fist', 'harp', 'gun', 'katana'] const Series = ['seraphic', 'grand', 'opus', 'draconic', 'revenant', 'primal', 'beast','regalia', 'omega', 'olden_primal', 'hollowsky', 'xeno', 'astral', 'rose', 'ultima', 'bahamut', 'epic', 'ennead', 'cosmos', 'ancestral', 'superlative', 'vintage', 'class_champion', 'sephira', 'new_world_foundation'] -class WeaponResult extends React.Component { - render() { - const weapon = this.props.data +const WeaponResult = (props: Props) => { + const router = useRouter() + const locale = (router.locale && ['en', 'ja'].includes(router.locale)) ? router.locale : 'en' + const weapon = props.data - return ( -
  • - {weapon.name.en} -
    -
    {weapon.name.en}
    - -
    - - -
    + return ( +
  • + {weapon.name[locale]} +
    +
    {weapon.name[locale]}
    + +
    + +
    -
  • - ) - } + + + ) } export default WeaponResult \ No newline at end of file