Rename variables, show only relevant event types

This commit is contained in:
Vencislav Atanasov 2024-10-01 20:02:53 +03:00
parent b3585ee1ce
commit d08d52a361
2 changed files with 31 additions and 17 deletions

View File

@ -16,11 +16,11 @@ export default function Schedule({
lang, lang,
}) { }) {
const { const {
speakers, speakers: allSpeakers,
tracks, tracks: allTracks,
eventTypes, eventTypes,
halls, halls,
events, events: allEvents,
slots, slots,
isLoading, isLoading,
loadingProgress, loadingProgress,
@ -32,10 +32,15 @@ export default function Schedule({
const { const {
header, header,
rows, rows,
speakers,
tracks,
events,
} = useScheduleTable({ } = useScheduleTable({
eventTypeId, eventTypeId,
speakers: allSpeakers,
tracks: allTracks,
halls, halls,
events, events: allEvents,
slots, slots,
}); });

View File

@ -5,27 +5,33 @@ import { compareAsc, getTime, isSameDay, toDate } from 'date-fns';
export default function useScheduleTable({ export default function useScheduleTable({
eventTypeId, eventTypeId,
halls = {}, speakers: allSpeakers = [],
events = {}, tracks: allTracks = [],
slots = {}, halls: allHalls = [],
events: allEvents = [],
slots: allSlots = [],
}) { }) {
return useMemo(() => { return useMemo(() => {
const filteredEvents = events.filter(event => eventTypeId > 0 ? event.event_type_id === eventTypeId : true); const events = allEvents.filter(event => eventTypeId > 0 ? event.event_type_id === eventTypeId : true);
const filteredEventIds = filteredEvents.map(event => event.id); const eventIds = events.map(event => event.id);
const filteredSlots = slots.sort(sorter('starts_at')).filter(slot => filteredEventIds.includes(slot.event_id)); const speakerIds = events.flatMap(event => event.participant_user_ids);
const microslots = Array.from(new Set(filteredSlots.flatMap(slot => [ const speakers = allSpeakers.filter(speaker => speakerIds.includes(speaker.id));
const trackIds = Array.from(new Set(events.map(event => event.track_id)));
const tracks = allTracks.filter(track => trackIds.includes(track.id));
const slots = allSlots.sort(sorter('starts_at')).filter(slot => eventIds.includes(slot.event_id));
const microslots = Array.from(new Set(slots.flatMap(slot => [
getTime(slot.starts_at), getTime(slot.starts_at),
getTime(slot.ends_at), getTime(slot.ends_at),
]))).sort().map(ts => toDate(ts)); ]))).sort().map(ts => toDate(ts));
const filteredHallIds = new Set(filteredSlots.map(slot => slot.hall_id)); const hallIds = new Set(slots.map(slot => slot.hall_id));
const filteredHalls = halls.filter(hall => filteredHallIds.has(hall.id)); const halls = allHalls.filter(hall => hallIds.has(hall.id));
const skipHallSlots = new Map(); const skipHallSlots = new Map();
const header = [{ const header = [{
id: 0, id: 0,
name: Object.fromEntries(Object.keys(langs).map(lang => [lang, ''])), name: Object.fromEntries(Object.keys(langs).map(lang => [lang, ''])),
}, },
...filteredHalls, ...halls,
]; ];
const rows = microslots.flatMap((date, slotsIndex, slotsArray) => { const rows = microslots.flatMap((date, slotsIndex, slotsArray) => {
@ -36,7 +42,7 @@ export default function useScheduleTable({
const isLastForTheDay = slotsArray?.[slotsIndex + 1] && !isSameDay(date, slotsArray[slotsIndex + 1]); const isLastForTheDay = slotsArray?.[slotsIndex + 1] && !isSameDay(date, slotsArray[slotsIndex + 1]);
const rowEvents = new Set(); const rowEvents = new Set();
const eventCells = filteredHalls.flatMap((hall, hallIndex, hallsArray) => { const eventCells = halls.flatMap((hall, hallIndex, hallsArray) => {
if (skipHallSlots.has(hall.id)) { if (skipHallSlots.has(hall.id)) {
const leftToSkip = skipHallSlots.get(hall.id); const leftToSkip = skipHallSlots.get(hall.id);
@ -50,7 +56,7 @@ export default function useScheduleTable({
return []; return [];
} }
const currentTimeSlots = filteredSlots.filter(slot => compareAsc(slot.starts_at, date) === 0); const currentTimeSlots = slots.filter(slot => compareAsc(slot.starts_at, date) === 0);
const currentHallSlot = currentTimeSlots.find(slot => slot.hall_id === hall.id); const currentHallSlot = currentTimeSlots.find(slot => slot.hall_id === hall.id);
if (!currentHallSlot) { if (!currentHallSlot) {
@ -144,6 +150,9 @@ export default function useScheduleTable({
return { return {
header, header,
rows, rows,
tracks,
events,
speakers,
}; };
}, [eventTypeId, events, halls, slots]); }, [eventTypeId, allSpeakers, allTracks, allEvents, allHalls, allSlots]);
} }