Simplified import starting with React. Added name property to group object passed to table. changed group interface shape.

;

;

l
;
d
This commit is contained in:
Maciek Głowacki 2020-09-18 23:00:11 +02:00
parent e90ffbe04d
commit 0ae374a0fb
5 changed files with 22 additions and 15 deletions

View File

@ -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.trim(), id: parseInt(id), lecture: null, classes: null }; const course: Basket = { name: name.trim(), id: parseInt(id) };
addToBasket(course); addToBasket(course);
setOpen(false); setOpen(false);

View File

@ -1,4 +1,4 @@
import React, { useContext, useEffect, useState } from 'react'; import React, { useContext, useEffect, useState, MouseEvent } 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';
@ -7,7 +7,7 @@ interface SchedulerEventsProps {
cellTop: number; cellTop: number;
cellWidth: number; cellWidth: number;
cellHeight: number; cellHeight: number;
onClick: (e: React.MouseEvent) => void onClick: (e: MouseEvent) => void;
} }
export const SchedulerEvents = ({ cellTop, cellWidth, cellHeight, onClick }: SchedulerEventsProps) => { export const SchedulerEvents = ({ cellTop, cellWidth, cellHeight, onClick }: SchedulerEventsProps) => {
@ -29,17 +29,24 @@ export const SchedulerEvents = ({ cellTop, cellWidth, cellHeight, onClick }: Sch
useEffect(() => { useEffect(() => {
function mapGroupTimeToEventRow(basket: Array<Basket>) { function mapGroupTimeToEventRow(basket: Array<Basket>) {
const classes = basket.map(({ classes }) => classes).filter((cl) => cl !== null) as Array<Group>; const classes = basket.map(({ classes, name }) => ({ ...classes, name })).filter((cl) => cl !== null) as Array<
const lectures = basket.map(({ lecture }) => lecture).filter((lec) => lec !== null) as Array<Group>; Group & { name: string }
>;
const lectures = basket.map(({ lecture, name }) => ({ ...lecture, name })).filter((lec) => lec !== null) as Array<
Group & { name: string }
>;
const merged = [...classes, ...lectures]; const merged = [...classes, ...lectures];
console.log('merged');
console.log(merged);
if (merged.length >= 1) { if (merged.length >= 1) {
const groupsMapped = merged.map(({ id, day, lecturer, room, time }) => ({ const groupsMapped = merged.map(({ id, day, lecturer, room, time, name }) => ({
id, id,
day, day,
lecturer, lecturer,
room, room,
eventRow: groupTimeToEventRowMapping[time], eventRow: groupTimeToEventRowMapping[time],
name,
})); }));
setChoosenGroupsMappedToEvents(groupsMapped); setChoosenGroupsMappedToEvents(groupsMapped);
} }

View File

@ -1,4 +1,4 @@
import React from 'react'; import React, { MouseEvent } from 'react';
import { Group } from '../types'; import { Group } from '../types';
import styled from 'styled-components'; import styled from 'styled-components';
@ -26,12 +26,12 @@ const ClassDiv = styled.div<SchedulerEventProps>`
`; `;
interface SchedulerRowProps { interface SchedulerRowProps {
groups: Array<Group>; groups: Array<Group & { name: string }>;
indexRow: number; indexRow: number;
cellTop: number; cellTop: number;
cellWidth: number; cellWidth: number;
cellHeight: number; cellHeight: number;
onClick: (e: React.MouseEvent) => void; onClick: (e: MouseEvent) => void;
} }
export const SchedulerRow = ({ groups, indexRow, cellTop, cellWidth, cellHeight, onClick }: SchedulerRowProps) => { export const SchedulerRow = ({ groups, indexRow, cellTop, cellWidth, cellHeight, onClick }: SchedulerRowProps) => {
@ -58,7 +58,7 @@ export const SchedulerRow = ({ groups, indexRow, cellTop, cellWidth, cellHeight,
id={`eventRow${indexRow}eventCol${eventIndex}`} id={`eventRow${indexRow}eventCol${eventIndex}`}
key={index} key={index}
> >
{groups[index]?.lecturer} {groups[index].name}
</ClassDiv> </ClassDiv>
), ),
)} )}

View File

@ -1,4 +1,4 @@
import React, { useState, createContext, useEffect } from 'react'; import React, { useState, createContext, useEffect, ReactNode } from 'react';
import { Course, Group, Basket, GroupType } from '../types'; import { Course, Group, Basket, GroupType } from '../types';
import axios from 'axios'; import axios from 'axios';
@ -11,7 +11,7 @@ interface CourseContext {
export const coursesContext = createContext<CourseContext | null>(null); export const coursesContext = createContext<CourseContext | null>(null);
interface CoursesProviderProps { interface CoursesProviderProps {
children: React.ReactNode; children: ReactNode;
} }
export const CoursesProvider = ({ children }: CoursesProviderProps) => { export const CoursesProvider = ({ children }: CoursesProviderProps) => {

View File

@ -6,8 +6,8 @@ export enum GroupType {
export interface Basket { export interface Basket {
id: number; id: number;
name: string; name: string;
lecture: Group | null; lecture?: Group;
classes: Group | null; classes?: Group;
} }
export interface Group { export interface Group {