From fff27f80918d00b4855570a6946119c17ed4bdd7 Mon Sep 17 00:00:00 2001 From: Nicole Zonnenberg Date: Mon, 17 Jul 2023 10:17:31 -0400 Subject: [PATCH] show conflicts --- frontend/assets/interfaces/Event.tsx | 1 + frontend/helpers/cleanData.tsx | 1 + frontend/pages/export/index.tsx | 95 ++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) diff --git a/frontend/assets/interfaces/Event.tsx b/frontend/assets/interfaces/Event.tsx index 64b99d02..5fa06dee 100644 --- a/frontend/assets/interfaces/Event.tsx +++ b/frontend/assets/interfaces/Event.tsx @@ -28,6 +28,7 @@ export interface NewEvent { title: string; tournament?: boolean website?: string; + conflicts?: number[]; } export interface RawEvent { diff --git a/frontend/helpers/cleanData.tsx b/frontend/helpers/cleanData.tsx index 0224ef1f..8eab5a39 100644 --- a/frontend/helpers/cleanData.tsx +++ b/frontend/helpers/cleanData.tsx @@ -66,6 +66,7 @@ export const cleanData = ({ keyList, eventList }: { var newEvent: NewEvent = { id: 0, ageRequirement: '', + conflicts: [], contact: '', cost: 0, descriptionShort: '', diff --git a/frontend/pages/export/index.tsx b/frontend/pages/export/index.tsx index b9f14872..b72db494 100644 --- a/frontend/pages/export/index.tsx +++ b/frontend/pages/export/index.tsx @@ -1,10 +1,82 @@ import { filteredEvents } from "@/pages/_app"; +import findEvent from "@/helpers/findEvent"; +import { NewEvent } from "@/assets/interfaces"; const eventsListByDay = filteredEvents.startDates; const eventsListByStartTime = filteredEvents.startTimes; +const eventsListByEndDate = filteredEvents.endDates; +const eventsListByEndTime = filteredEvents.endTimes; const dayLabels = Object.keys(eventsListByDay).sort(); const timeLabels = Object.keys(eventsListByStartTime).sort(); +const findConflicts = (favesList: number[], favesMasterList: number[]) => { + var faveDetails: NewEvent[] = []; + + favesList.map((fave, index) => { + var faveEvent = findEvent(fave), + conflictingEvents: number[] = []; + + // Find events that start at same time; + favesMasterList.filter(val => { + if (eventsListByStartTime[faveEvent.startTime].includes(val) + && eventsListByDay[faveEvent.startDate].includes(val) + && val != faveEvent.id + && !conflictingEvents.includes(val)) { + conflictingEvents.push(val); + } + }) + + // Find events that end at same time; + favesMasterList.filter(val => { + if (eventsListByEndTime[faveEvent.endTime].includes(val) + && eventsListByDay[faveEvent.endDate].includes(val) + && val != faveEvent.id + && !conflictingEvents.includes(val)) { + conflictingEvents.push(val); + } + }) + + // Find events that starts during the duration + favesMasterList.filter(val => { + var valueEvent = findEvent(val) + if ((eventsListByDay[faveEvent.startDate].includes(val) || eventsListByDay[faveEvent.endDate].includes(val)) + && (valueEvent.startTime > faveEvent.startTime && valueEvent.startTime < faveEvent.endTime) + && !conflictingEvents.includes(val)) { + conflictingEvents.push(val); + } + }) + + // Find events that ends during the duration + favesMasterList.filter(val => { + var valueEvent = findEvent(val) + if ((eventsListByDay[faveEvent.startDate].includes(val) + || eventsListByDay[faveEvent.endDate].includes(val)) + && (valueEvent.endTime > faveEvent.startTime + && valueEvent.endTime < faveEvent.endTime) + && !conflictingEvents.includes(val)) { + conflictingEvents.push(val); + } + }) + + // Find events that are too long + favesMasterList.filter(val => { + var valueEvent = findEvent(val) + if ((eventsListByDay[faveEvent.startDate].includes(val) + && eventsListByDay[faveEvent.endDate].includes(val)) + && (valueEvent.startTime < faveEvent.startTime && valueEvent.endTime > faveEvent.endTime) + && !conflictingEvents.includes(val)) { + conflictingEvents.push(val); + } + }) + + faveEvent.conflicts = conflictingEvents; + + faveDetails.push(faveEvent) + }) + + return faveDetails; +} + export default function ExportPage () { const faves = JSON.parse(localStorage.getItem('faves') || '[]'); @@ -35,12 +107,35 @@ export default function ExportPage () { {timeLabels.map((time, index) => { const favesPerTime = favesPerDay.filter(val => eventsListByStartTime[time].includes(val)); + const faveEventsList = findConflicts(favesPerTime, faves) + if (favesPerTime.length) { return ( ) }