Skip to content

Commit

Permalink
show conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Sun-Mountain committed Jul 17, 2023
1 parent bc31532 commit fff27f8
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
1 change: 1 addition & 0 deletions frontend/assets/interfaces/Event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface NewEvent {
title: string;
tournament?: boolean
website?: string;
conflicts?: number[];
}

export interface RawEvent {
Expand Down
1 change: 1 addition & 0 deletions frontend/helpers/cleanData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const cleanData = ({ keyList, eventList }: {
var newEvent: NewEvent = {
id: 0,
ageRequirement: '',
conflicts: [],
contact: '',
cost: 0,
descriptionShort: '',
Expand Down
95 changes: 95 additions & 0 deletions frontend/pages/export/index.tsx
Original file line number Diff line number Diff line change
@@ -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') || '[]');

Expand Down Expand Up @@ -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 (
<ul className='schedule-list-time' key={index}>
<li>
{time}
</li>
<ul>
{faveEventsList.map((fave, index) => {
return (
<li key={index}>
<strong>{fave.title}</strong>
<div>
<ul>
{fave.conflicts?.map((conflict, index) => {
var conflictName = findEvent(conflict);
return (
<li key={index}>
{conflict} - {conflictName.title}
</li>
)
})}
</ul>
</div>
</li>
)
})}
</ul>
</ul>
)
}
Expand Down

0 comments on commit fff27f8

Please sign in to comment.