Skip to content

Commit

Permalink
type fixs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tacio Medeiros committed Apr 1, 2024
1 parent 44aef1d commit 590e1be
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const ScheduleSection: React.FC<SpeakersSectionProps> = ({ speakers, schedule })
<Row className={styles.height100p}>
{
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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpeakersSectionProps> = ({ speakers, schedule }) => {
const speakersMap = new Map(speakers.map((speaker) => ([speaker.key, speaker])));

return (
<>
{speakers.length &&
Expand All @@ -43,29 +54,22 @@ export const ScheduleSection: React.FC<SpeakersSectionProps> = ({ speakers, sche
{commonSpeeches.length && (
<section className={styles.schedule_grid}>
{commonSpeeches.map((speeches) => (
<ScheduleCard
key={generateKey(speeches)}
<ScheduleCard
key={generateKey(speeches)}
speech={speeches}
speakers={
speeches.speakerSlugs
? speeches.speakerSlugs.map((slug) => speakersMap.get(slug)!)
: []
}
speakers={getSpeakers(speeches, speakersMap)}

/>
))}
</section>
)}
{speedSpeeches.length > 0 && (
<section className={styles.schedule_grid}>
{speedSpeeches.map((speeches, i) => (
<ScheduleCard
key={generateKey(speeches)}
<ScheduleCard
key={generateKey(speeches)}
speech={speeches}
speakers={
speeches.speakerSlugs
? speeches.speakerSlugs.map((slug) => speakersMap.get(slug)!)
: []
}
speakers={getSpeakers(speeches, speakersMap)}
/>
))}
</section>
Expand Down
9 changes: 6 additions & 3 deletions src/models/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,11 +14,14 @@ export interface ScheduleSpeech {
end: string;
}

export interface ScheduleMultipleSpeech extends ScheduleSpeech {
speakerKeys: Array<string>;
speakerKey: never;
}

export interface ScheduleSpeedSpeech extends ScheduleSpeech {
duration: number;
}

// TODO: rename enum to correct path names
export enum SpeechesPath {
MINAS = "MINAS", // principal
CURADO = "CURADO",
Expand Down

0 comments on commit 590e1be

Please sign in to comment.