From 590e1be21922c7cfdb9c02e1977b1260444203c6 Mon Sep 17 00:00:00 2001 From: Tacio Medeiros Date: Mon, 1 Apr 2024 17:35:59 -0300 Subject: [PATCH] type fixs --- .../schedule-section/schedule-section.tsx | 2 +- .../schedule-section/schedule-section.tsx | 40 ++++++++++--------- src/models/schedule.ts | 9 +++-- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/components/devfest-cerrado-2022/schedule-section/schedule-section.tsx b/src/components/devfest-cerrado-2022/schedule-section/schedule-section.tsx index d4caaa7..eb20f5b 100644 --- a/src/components/devfest-cerrado-2022/schedule-section/schedule-section.tsx +++ b/src/components/devfest-cerrado-2022/schedule-section/schedule-section.tsx @@ -35,7 +35,7 @@ const ScheduleSection: React.FC = ({ speakers, schedule }) { schedule.speeches?.map((speech, index) => { - const speaker = speakers.find(speakerObj => speech.speakerSlugs.find((slug) => speakerObj.key === slug)); + const speaker = speakers.find(speakerObj => speakerObj.key === speech.speakerKey); // console.log("speaker: " + JSON.stringify(speaker)) if (speech?.topic) { return ( diff --git a/src/components/devfest-triangulo-2023/schedule-section/schedule-section.tsx b/src/components/devfest-triangulo-2023/schedule-section/schedule-section.tsx index 68b4504..65ba0d7 100644 --- a/src/components/devfest-triangulo-2023/schedule-section/schedule-section.tsx +++ b/src/components/devfest-triangulo-2023/schedule-section/schedule-section.tsx @@ -17,14 +17,25 @@ interface SpeakersSectionProps { } function generateKey(speech: Speeches) { - return `speech-${speech.path}-${ - speech.speakerSlugs ? speech.speakerSlugs.map((slug) => slug).join('-') : speech.topic - }` + return `speech-${speech.path}-${speech.start}-${speech.end}`; +} + +const getSpeakers = (speech: Speeches, speakersMap: any) => { + + if (speech.speakerKey) { + return [speech.speakerKey]; + } + + if ('speakerKeys' in speech) { + return speech.speakerKeys.map((speakerKey) => speakersMap.get(speakerKey)); + } + + return []; } export const ScheduleSection: React.FC = ({ speakers, schedule }) => { const speakersMap = new Map(speakers.map((speaker) => ([speaker.key, speaker]))); - + return ( <> {speakers.length && @@ -43,14 +54,11 @@ export const ScheduleSection: React.FC = ({ speakers, sche {commonSpeeches.length && (
{commonSpeeches.map((speeches) => ( - speakersMap.get(slug)!) - : [] - } + speakers={getSpeakers(speeches, speakersMap)} + /> ))}
@@ -58,14 +66,10 @@ export const ScheduleSection: React.FC = ({ speakers, sche {speedSpeeches.length > 0 && (
{speedSpeeches.map((speeches, i) => ( - speakersMap.get(slug)!) - : [] - } + speakers={getSpeakers(speeches, speakersMap)} /> ))}
diff --git a/src/models/schedule.ts b/src/models/schedule.ts index c1dd90a..bf9795e 100644 --- a/src/models/schedule.ts +++ b/src/models/schedule.ts @@ -4,7 +4,7 @@ export interface Schedule { speeches: Speeches[] } -export type Speeches = (ScheduleSpeech | ScheduleSpeedSpeech); +export type Speeches = ScheduleSpeech | ScheduleSpeedSpeech | ScheduleMultipleSpeech; export interface ScheduleSpeech { topic: string; @@ -14,11 +14,14 @@ export interface ScheduleSpeech { end: string; } +export interface ScheduleMultipleSpeech extends ScheduleSpeech { + speakerKeys: Array; + speakerKey: never; +} + export interface ScheduleSpeedSpeech extends ScheduleSpeech { duration: number; } - -// TODO: rename enum to correct path names export enum SpeechesPath { MINAS = "MINAS", // principal CURADO = "CURADO",