Skip to content

Commit

Permalink
#74 introduced otherSpeakers in lineup talk firestore model + provide…
Browse files Browse the repository at this point in the history
…d voxxrin model mappers for lineup speakers/talks
  • Loading branch information
fcamblor committed Oct 30, 2024
1 parent c83e0e6 commit df0bccf
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 7 deletions.
1 change: 1 addition & 0 deletions cloud/functions/src/models/Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function detailedTalksToSpeakersLineup(talks: DetailedTalk[]): LineupSpea
start: talk.start,
end: talk.end,
},
otherSpeakers: talk.speakers.filter(sp => sp.id !== speaker.id),
})
})
return speakers;
Expand Down
59 changes: 59 additions & 0 deletions mobile/src/models/VoxxrinSpeaker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,66 @@
import {ValueObject} from "@/models/utils";
import {Speaker} from "../../../shared/daily-schedule.firestore";
import {Replace} from "../../../shared/type-utils";
import {LineupSpeaker, LineupTalk} from "../../../shared/event-lineup.firestore";
import {TalkId} from "@/models/VoxxrinTalk";
import {RoomId, VoxxrinRoom} from "@/models/VoxxrinRoom";
import {findRoom, findTalkFormat, findTrack, VoxxrinConferenceDescriptor} from "@/models/VoxxrinConferenceDescriptor";
import {match, P} from "ts-pattern";
import {TalkFormatId, VoxxrinTalkFormat} from "@/models/VoxxrinTalkFormat";
import {TrackId, VoxxrinTrack} from "@/models/VoxxrinTrack";

export class SpeakerId extends ValueObject<string>{ _speakerIdClassDiscriminator!: never; }
export type VoxxrinDetailedSpeaker = Replace<Speaker, {id: SpeakerId}>;
export type VoxxrinSimpleSpeaker = Omit<VoxxrinDetailedSpeaker, "bio"|"social">;

export type VoxxrinLineupTalk = Replace<LineupTalk, {
id: TalkId,
format: VoxxrinTalkFormat,
track: VoxxrinTrack,
allocation: {
room: VoxxrinRoom,
}|undefined,
otherSpeakers: VoxxrinSimpleSpeaker[],
}>

export type VoxxrinLineupSpeaker = Replace<LineupSpeaker, {
id: SpeakerId,
talks: VoxxrinLineupTalk[],
}>

export const toVoxxrinSpeaker = (speaker: Speaker): VoxxrinSimpleSpeaker => {
return ({
photoUrl: speaker.photoUrl,
companyName: speaker.companyName,
fullName: speaker.fullName,
id: new SpeakerId(speaker.id)
})
}

export const createVoxxrinSpeakerFromFirestore = (conferenceDescriptor: VoxxrinConferenceDescriptor, firestoreSpeaker: LineupSpeaker): VoxxrinLineupSpeaker => {
return {
...firestoreSpeaker,
id: new SpeakerId(firestoreSpeaker.id),
talks: firestoreSpeaker.talks.map(firestoreTalk => {
const format = findTalkFormat(conferenceDescriptor, new TalkFormatId(firestoreTalk.format.id));
const track = findTrack(conferenceDescriptor, new TrackId(firestoreTalk.track.id));
const allocation = match(firestoreTalk.allocation)
.with(P.not(P.nullish), allocation => {
const room = findRoom(conferenceDescriptor, new RoomId(allocation.room.id));
return {
...firestoreTalk.allocation,
room
};
}).otherwise(() => undefined);

return {
...firestoreTalk,
id: new TalkId(firestoreTalk.id),
allocation,
format,
track,
otherSpeakers: firestoreTalk.otherSpeakers.map(sp => toVoxxrinSpeaker(sp)),
};
})
}
}
9 changes: 2 additions & 7 deletions mobile/src/models/VoxxrinTalk.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {sortBy, ValueObject} from "@/models/utils";
import {Break, DetailedTalk, Talk, TalkAsset} from "../../../shared/daily-schedule.firestore";
import {RoomId, VoxxrinRoom} from "@/models/VoxxrinRoom";
import {SpeakerId, VoxxrinDetailedSpeaker, VoxxrinSimpleSpeaker} from "@/models/VoxxrinSpeaker";
import {SpeakerId, toVoxxrinSpeaker, VoxxrinDetailedSpeaker, VoxxrinSimpleSpeaker} from "@/models/VoxxrinSpeaker";
import {TalkFormatId, VoxxrinTalkFormat} from "@/models/VoxxrinTalkFormat";
import {TrackId, VoxxrinTrack} from "@/models/VoxxrinTrack";
import {
Expand Down Expand Up @@ -48,12 +48,7 @@ export function createVoxxrinTalkFromFirestore(event: VoxxrinConferenceDescripto
const talk: VoxxrinTalk = {
language: new TalkLanguageCode(firestoreTalk.language),
title: firestoreTalk.title,
speakers: firestoreTalk.speakers.map(sp => ({
photoUrl: sp.photoUrl,
companyName: sp.companyName,
fullName: sp.fullName,
id: new SpeakerId(sp.id)
})),
speakers: firestoreTalk.speakers.map(sp => toVoxxrinSpeaker(sp)),
format,
track,
room,
Expand Down
1 change: 1 addition & 0 deletions shared/event-lineup.firestore.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type LineupTalk = {
start: ISODatetime,
end: ISODatetime,
}|undefined,
otherSpeakers: Speaker[],
}

export type LineupSpeaker = Speaker & {
Expand Down

0 comments on commit df0bccf

Please sign in to comment.