diff --git a/package.json b/package.json index 35483f8..6fc9bd6 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@focus-reactive/graphql-content-layer", - "version": "3.2.1", + "version": "3.2.2", "private": false, "main": "dist/index.js", "scripts": { diff --git a/src/fetch-speakers.js b/src/fetch-speakers.js index 520ea7a..b4acc70 100644 --- a/src/fetch-speakers.js +++ b/src/fetch-speakers.js @@ -1,7 +1,7 @@ const { prepareSpeakers, trySelectSettings, sortByOrder } = require('./utils'); const { speakerInfoFragment, sponsorLogoFragment } = require('./fragments'); const dayjs = require('dayjs'); -const { getSpeakers } = require('./http-utils'); +const { getSpeakers, getPastSpeakers } = require('./http-utils'); const selectSettings = trySelectSettings( s => ({ @@ -145,17 +145,43 @@ const fetchData = async (client, { tagColors, labelColors, ...vars }) => { emsEventId: res.conf.year[0].emsEventId, useEmsData: res.conf.year[0].useEmsData, })); - const emsSpeakers = data.useEmsData && (await getSpeakers(data.emsEventId)); + + let emsSpeakers, pastSpeakers; + if (data.useEmsData) { + [emsSpeakers, pastSpeakers] = await Promise.all([ + getSpeakers(data.emsEventId), + getPastSpeakers(data.emsEventId), + ]); + } const { openForTalks } = data; - const convertDateToIso = item => ({ - ...item, - timeString: item.timeString ? dayjs(item.timeString).toISOString() : null, - }); + const [ + { daySpeakers, eveningSpeakers }, + { daySpeakers: daySpeakersPast, eveningSpeakers: eveningSpeakersPast }, + ] = await Promise.all([emsSpeakers || data.speakers, pastSpeakers].map(speakers => + processSpeakers(speakers, tagColors, labelColors) + )); + + return { + speakers: { main: daySpeakers }, + eveningSpeakers, + pastSpeakers: { + main: daySpeakersPast, + eveningSpeakers: eveningSpeakersPast, + }, + speakersBtn: openForTalks ? 'CALL FOR SPEAKERS' : false, + labelColors, + }; +}; + +const convertDateToIso = item => ({ + ...item, + timeString: item.timeString ? dayjs(item.timeString).toISOString() : null, +}); - const speakersRaw = emsSpeakers || data.speakers; - const speakersWithPlainActivities = speakersRaw.map(speaker => { +const processSpeakers = async (rawSpeakers, tagColors, labelColors) => { + const speakersWithPlainActivities = rawSpeakers.map(speaker => { if (!speaker.activities) { console.log('invalid activities', JSON.stringify(speaker)); } @@ -214,12 +240,7 @@ const fetchData = async (client, { tagColors, labelColors, ...vars }) => { ({ isNightSpeaker }) => isNightSpeaker, ); - return { - speakers: { main: daySpeakers }, - eveningSpeakers, - speakersBtn: openForTalks ? 'CALL FOR SPEAKERS' : false, - labelColors, - }; + return { daySpeakers, eveningSpeakers }; }; module.exports = { diff --git a/src/http-utils.js b/src/http-utils.js index d2c2b6d..83da1db 100644 --- a/src/http-utils.js +++ b/src/http-utils.js @@ -17,6 +17,7 @@ const baseEventFetch = path => { }; const getSpeakers = baseEventFetch('speakers'); +const getPastSpeakers = baseEventFetch('speakers/past'); const getPartners = baseEventFetch('partners'); const getTopSpeaker = baseEventFetch('speakers/top'); const getSchedule = baseEventFetch('schedule'); @@ -29,6 +30,7 @@ const getEvent = baseEventFetch(''); module.exports = { getSpeakers, + getPastSpeakers, getPartners, getSchedule, getTopSpeaker,