From 15c03b146f1ed1964a9d773a124e3bd480e9c7c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciek=20G=C5=82owacki?= Date: Wed, 26 Aug 2020 18:42:29 +0200 Subject: [PATCH] you can add lectures now: : --- src/components/CourseCard.tsx | 2 -- src/components/Dropdown.tsx | 2 +- src/components/Rightbar.tsx | 4 ++-- src/components/SchedulerEvents.tsx | 30 ++++++++++++++---------------- src/contexts/CoursesProvider.tsx | 10 ++-------- 5 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/components/CourseCard.tsx b/src/components/CourseCard.tsx index 4995caf..eb42f7b 100644 --- a/src/components/CourseCard.tsx +++ b/src/components/CourseCard.tsx @@ -79,8 +79,6 @@ export const CourseCard = ({ onCardClick, course, id, isSelected }: CourseCardPr const { addGroup } = useContext(coursesContext)!; - console.log(`course`); - console.log(course); const onGroupClick = (group: Group, id: number) => addGroup(group, id); return ( diff --git a/src/components/Dropdown.tsx b/src/components/Dropdown.tsx index f77da72..4defa11 100644 --- a/src/components/Dropdown.tsx +++ b/src/components/Dropdown.tsx @@ -83,7 +83,7 @@ export const Dropdown = ({ clearInput, handleClearInput }: DropdownProps) => { const name = target.textContent; //porozmawiać z Filipem, żeby odrobinę przerobił endpoint - const course: Basket = { name: name, id: parseInt(id), lecture: null, classes: null }; + const course: Basket = { name: name.trim(), id: parseInt(id), lecture: null, classes: null }; addToBasket(course); setOpen(false); diff --git a/src/components/Rightbar.tsx b/src/components/Rightbar.tsx index 5262df5..874ec0a 100644 --- a/src/components/Rightbar.tsx +++ b/src/components/Rightbar.tsx @@ -36,8 +36,8 @@ export const Rightbar = () => { const { courses, basket } = useContext(coursesContext)!; const getBasketGroups = () => { - const ids = basket.map(({ id }) => id); - return courses.filter(({ id }) => ids.includes(id)); + const names = basket.map(({ name }) => name); + return courses.filter(({ name }) => names.includes(name)); }; const filteredCourses = getBasketGroups(); diff --git a/src/components/SchedulerEvents.tsx b/src/components/SchedulerEvents.tsx index 3a57cc1..304d658 100644 --- a/src/components/SchedulerEvents.tsx +++ b/src/components/SchedulerEvents.tsx @@ -2,6 +2,7 @@ import React, { useContext, useEffect, useState } from 'react'; import { SchedulerRow } from './SchedulerRow'; import { coursesContext } from '../contexts/CoursesProvider'; import { Group, Basket } from '../types'; +import classes from '*.module.css'; interface SchedulerEventsProps { cellTop: number; @@ -27,23 +28,20 @@ export const SchedulerEvents = ({ cellTop, cellWidth }: SchedulerEventsProps) => useEffect(() => { function mapGroupTimeToEventRow(basket: Array) { - const basketGroups = basket.map(({ classes, lecture }) => ({ - ...classes, - ...lecture, - })) as Array; + const classes = basket.map(({ classes }) => classes).filter((cl) => cl !== null) as Array; + const lectures = basket.map(({ lecture }) => lecture).filter((lec) => lec !== null) as Array; + const merged = [...classes, ...lectures]; - console.log('passed basket'); - console.log(basket); - console.log(`basketgroups`); - console.log(basketGroups); - const groupsMapped = basketGroups.map(({ id, day, lecturer, room, time }) => ({ - id, - day, - lecturer, - room, - eventRow: groupTimeToEventRowMapping[time], - })); - setChoosenGroupsMappedToEvents(groupsMapped); + if (merged.length >= 1) { + const groupsMapped = merged.map(({ id, day, lecturer, room, time }) => ({ + id, + day, + lecturer, + room, + eventRow: groupTimeToEventRowMapping[time], + })); + setChoosenGroupsMappedToEvents(groupsMapped); + } } mapGroupTimeToEventRow(basket); }, [basket]); diff --git a/src/contexts/CoursesProvider.tsx b/src/contexts/CoursesProvider.tsx index 7b49128..722b80b 100644 --- a/src/contexts/CoursesProvider.tsx +++ b/src/contexts/CoursesProvider.tsx @@ -44,14 +44,8 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => { useEffect(() => { const fetchData = async () => { - const { data: courses } = await axios.get(`${process.env.REACT_APP_API_URL}/getCourses`); - - for (const course of courses) { - const { data: groups } = await axios.get(`${process.env.REACT_APP_API_URL}/getCourseGroups?id=${course.id}`); - //porozmawiać z Filipem, żeby odrobinę przerobił endpoint - course.groups = groups; - } - + const { data: courses } = await axios.get(`${process.env.REACT_APP_API_URL}/getCoursesWithGroups`); + courses.sort((a: Course, b: Course) => (a.name > b.name ? 1 : -1)); setCourses(courses); }; fetchData();