you can add lectures now:
:
This commit is contained in:
		| @@ -79,8 +79,6 @@ export const CourseCard = ({ onCardClick, course, id, isSelected }: CourseCardPr | |||||||
|  |  | ||||||
|   const { addGroup } = useContext(coursesContext)!; |   const { addGroup } = useContext(coursesContext)!; | ||||||
|  |  | ||||||
|   console.log(`course`); |  | ||||||
|   console.log(course); |  | ||||||
|   const onGroupClick = (group: Group, id: number) => addGroup(group, id); |   const onGroupClick = (group: Group, id: number) => addGroup(group, id); | ||||||
|  |  | ||||||
|   return ( |   return ( | ||||||
|   | |||||||
| @@ -83,7 +83,7 @@ export const Dropdown = ({ clearInput, handleClearInput }: DropdownProps) => { | |||||||
|       const name = target.textContent; |       const name = target.textContent; | ||||||
|  |  | ||||||
|       //porozmawiać z Filipem, żeby odrobinę przerobił endpoint |       //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); |       addToBasket(course); | ||||||
|       setOpen(false); |       setOpen(false); | ||||||
|   | |||||||
| @@ -36,8 +36,8 @@ export const Rightbar = () => { | |||||||
|   const { courses, basket } = useContext(coursesContext)!; |   const { courses, basket } = useContext(coursesContext)!; | ||||||
|  |  | ||||||
|   const getBasketGroups = () => { |   const getBasketGroups = () => { | ||||||
|     const ids = basket.map(({ id }) => id); |     const names = basket.map(({ name }) => name); | ||||||
|     return courses.filter(({ id }) => ids.includes(id)); |     return courses.filter(({ name }) => names.includes(name)); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   const filteredCourses = getBasketGroups(); |   const filteredCourses = getBasketGroups(); | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ import React, { useContext, useEffect, useState } from 'react'; | |||||||
| import { SchedulerRow } from './SchedulerRow'; | import { SchedulerRow } from './SchedulerRow'; | ||||||
| import { coursesContext } from '../contexts/CoursesProvider'; | import { coursesContext } from '../contexts/CoursesProvider'; | ||||||
| import { Group, Basket } from '../types'; | import { Group, Basket } from '../types'; | ||||||
|  | import classes from '*.module.css'; | ||||||
|  |  | ||||||
| interface SchedulerEventsProps { | interface SchedulerEventsProps { | ||||||
|   cellTop: number; |   cellTop: number; | ||||||
| @@ -27,23 +28,20 @@ export const SchedulerEvents = ({ cellTop, cellWidth }: SchedulerEventsProps) => | |||||||
|  |  | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|     function mapGroupTimeToEventRow(basket: Array<Basket>) { |     function mapGroupTimeToEventRow(basket: Array<Basket>) { | ||||||
|       const basketGroups = basket.map(({ classes, lecture }) => ({ |       const classes = basket.map(({ classes }) => classes).filter((cl) => cl !== null) as Array<Group>; | ||||||
|         ...classes, |       const lectures = basket.map(({ lecture }) => lecture).filter((lec) => lec !== null) as Array<Group>; | ||||||
|         ...lecture, |       const merged = [...classes, ...lectures]; | ||||||
|       })) as Array<Group>; |  | ||||||
|  |  | ||||||
|       console.log('passed basket'); |       if (merged.length >= 1) { | ||||||
|       console.log(basket); |         const groupsMapped = merged.map(({ id, day, lecturer, room, time }) => ({ | ||||||
|       console.log(`basketgroups`); |           id, | ||||||
|       console.log(basketGroups); |           day, | ||||||
|       const groupsMapped = basketGroups.map(({ id, day, lecturer, room, time }) => ({ |           lecturer, | ||||||
|         id, |           room, | ||||||
|         day, |           eventRow: groupTimeToEventRowMapping[time], | ||||||
|         lecturer, |         })); | ||||||
|         room, |         setChoosenGroupsMappedToEvents(groupsMapped); | ||||||
|         eventRow: groupTimeToEventRowMapping[time], |       } | ||||||
|       })); |  | ||||||
|       setChoosenGroupsMappedToEvents(groupsMapped); |  | ||||||
|     } |     } | ||||||
|     mapGroupTimeToEventRow(basket); |     mapGroupTimeToEventRow(basket); | ||||||
|   }, [basket]); |   }, [basket]); | ||||||
|   | |||||||
| @@ -44,14 +44,8 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => { | |||||||
|  |  | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|     const fetchData = async () => { |     const fetchData = async () => { | ||||||
|       const { data: courses } = await axios.get(`${process.env.REACT_APP_API_URL}/getCourses`); |       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)); | ||||||
|       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; |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       setCourses(courses); |       setCourses(courses); | ||||||
|     }; |     }; | ||||||
|     fetchData(); |     fetchData(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user