Merge pull request 'you can add lectures now:' (#17) from add-lecture into master

Reviewed-on: http://git.plannaplan.pl/y0rune/frontend/pulls/17
Reviewed-by: wrzesinski-hubert <wrzesinski.hubert@gmail.com>
This commit is contained in:
wrzesinski-hubert 2020-08-26 18:42:46 +02:00
commit d30852b97d
5 changed files with 19 additions and 29 deletions

View File

@ -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 (

View File

@ -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);

View File

@ -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();

View File

@ -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,16 +28,12 @@ export const SchedulerEvents = ({ cellTop, cellWidth }: SchedulerEventsProps) =>
useEffect(() => {
function mapGroupTimeToEventRow(basket: Array<Basket>) {
const basketGroups = basket.map(({ classes, lecture }) => ({
...classes,
...lecture,
})) as Array<Group>;
const classes = basket.map(({ classes }) => classes).filter((cl) => cl !== null) as Array<Group>;
const lectures = basket.map(({ lecture }) => lecture).filter((lec) => lec !== null) as Array<Group>;
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 }) => ({
if (merged.length >= 1) {
const groupsMapped = merged.map(({ id, day, lecturer, room, time }) => ({
id,
day,
lecturer,
@ -45,6 +42,7 @@ export const SchedulerEvents = ({ cellTop, cellWidth }: SchedulerEventsProps) =>
}));
setChoosenGroupsMappedToEvents(groupsMapped);
}
}
mapGroupTimeToEventRow(basket);
}, [basket]);

View File

@ -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();