diff --git a/src/helpers/apiRequests.ts b/src/helpers/apiRequests.ts index f8ffc25..8987047 100644 --- a/src/helpers/apiRequests.ts +++ b/src/helpers/apiRequests.ts @@ -24,7 +24,7 @@ import { // Types import { ContactData, Contact } from "../types/contact"; import { Video } from "../types/video"; -import { playerType } from "../types/players"; +import { Player, playerType } from "../types/players"; import { About } from "../types/about"; export const getMainSliderData = ( @@ -154,11 +154,14 @@ export const getEvents = (setState: any) => { .catch(); }; -export const getPlayerInfo = (setState: any, link: string) => { +export const getPlayerInfo = ( + setState: React.Dispatch, + link: string +) => { axios .get(link) .then((res) => { - setState(res.data.data); + setState(res.data.data[0]); }) .catch(); }; diff --git a/src/pages/PlayerProfile.tsx b/src/pages/PlayerProfile.tsx index d91cdb1..4f5c47f 100644 --- a/src/pages/PlayerProfile.tsx +++ b/src/pages/PlayerProfile.tsx @@ -14,8 +14,18 @@ import useMediaQuery from "../hooks/useMediaQuery"; import { hosting } from "../links"; import { players } from "../links"; +// Types +import { Player } from "../types/players"; + const PlayerProfile = () => { - const [playerInfo, setPlayerInfo]: [any, React.Dispatch] = useState(); + const [playerInfo, setPlayerInfo]: [Player, React.Dispatch] = + useState({ + id: -1, + name: "", + average: -1, + national: -1, + img: "", + }); const { playerId } = useParams(); useEffect(() => { @@ -31,10 +41,13 @@ const PlayerProfile = () => {
-
- {playerInfo ? ( +
+ {playerInfo.id !== -1 ? (
- +
) : ( {
- {playerInfo ? ( -

{playerInfo[0].name}

+ {playerInfo.id !== -1 ? ( +

{playerInfo.name}

) : ( { )}
    - {playerInfo ? ( + {playerInfo.id !== -1 ? (
  • ID -

    {playerInfo[0].id}

    +

    {playerInfo.id}

  • ) : (
  • @@ -84,7 +97,7 @@ const PlayerProfile = () => { />
  • )} - {playerInfo ? ( + {playerInfo.id !== -1 ? (
  • Звание

    @@ -112,7 +125,7 @@ const PlayerProfile = () => { />

  • )} - {playerInfo ? ( + {playerInfo.id !== -1 ? (
  • Год рождения

    @@ -145,7 +158,7 @@ const PlayerProfile = () => {

- {playerInfo ? ( + {playerInfo.id !== -1 ? ( "Rating" ) : ( {

    - {playerInfo ? ( + {playerInfo.id !== -1 ? (
  • Classic -

    {playerInfo[0].average}

    +

    {playerInfo.average}

  • ) : (
  • @@ -183,7 +196,7 @@ const PlayerProfile = () => { />
  • )} - {playerInfo ? ( + {playerInfo.id !== -1 ? (
  • Rapid

    @@ -211,7 +224,7 @@ const PlayerProfile = () => { />

  • )} - {playerInfo ? ( + {playerInfo.id !== -1 ? (
  • Blitz