diff --git a/src/components/SpeakerInfo.tsx b/src/components/SpeakerInfo.tsx index 68850be..32d7663 100644 --- a/src/components/SpeakerInfo.tsx +++ b/src/components/SpeakerInfo.tsx @@ -1,6 +1,6 @@ import {ISpeaker} from "@/types/speakers.ts"; import {Card, CardFooter} from "@/components/ui/card.tsx"; -import React, {useEffect} from "react"; +import React, {useEffect, useState} from "react"; import {useLocation, useParams} from "react-router-dom"; import SocialMedia from "@/components/SocialMedia.tsx"; import {Badge} from "@/components/ui/badge.tsx"; @@ -9,35 +9,50 @@ import Gradient from "@/components/Gradient.tsx"; import {useAppContext} from "@/context/AppContext.tsx"; import {findSpeaker, scrollToTop} from "@/lib/utils.ts"; import Shared from "@/components/Shared.tsx"; +import Loading from "@/components/Loading.tsx"; const SpeakerInfo = () => { const location = useLocation(); const { speakerId } = useParams(); const { speakers } = useAppContext(); const speaker = location.state?.speaker as ISpeaker; - const {fullName, sessions, profilePicture, tagLine, bio, links} = speaker; + const [currentSpeaker, setCurrentSpeaker] = useState() const fullUrl = `${window.location.origin}${location.pathname}${location.search}${location.hash}`; useEffect(() => { scrollToTop() - if (speaker) return; - findSpeaker(speakers, speakerId) }, []); + useEffect(() => { + if (speaker == undefined) { + setCurrentSpeaker(findSpeaker(speakers, speakerId)) + } else { + setCurrentSpeaker(speaker); + } + }, [speaker, speakers]); + + if (!currentSpeaker) { + return ( +
+ +
+ ); + } + return (
- {fullName} + {currentSpeaker.fullName}
-

{fullName}

-

{tagLine}

-

{bio}

+

{currentSpeaker.fullName}

+

{currentSpeaker.tagLine}

+

{currentSpeaker.bio}

- {links.map((link) => ( + {currentSpeaker.links.map((link) => ( ))} - +
@@ -47,12 +62,12 @@ const SpeakerInfo = () => { Charla

- {sessions.title} + {currentSpeaker.sessions.title}

Descripción -

{sessions.description}

+

{currentSpeaker.sessions.description}

- Track: {speaker.category} + Track: {currentSpeaker.category}
diff --git a/src/context/AppContext.tsx b/src/context/AppContext.tsx index 49e9140..727f88b 100644 --- a/src/context/AppContext.tsx +++ b/src/context/AppContext.tsx @@ -24,8 +24,8 @@ export const AppProvider = ({ children }) => { getAll().then((data) => { const getSpeakersWithSessions = addSessionSpeakers(data.sessions, data.speakers, data.categories[0].items); setSpeakers(getSpeakersWithSessions); + setAppStatus(AppStatus.Success) }); - setAppStatus(AppStatus.Success) }, []); const value = {