From bef314120a2ef482fde5ca616aa63480a967b900 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 24 Jul 2020 18:59:45 +0200 Subject: [PATCH] Dej te endpointy --- src/businesslogic/LecturesProvider.tsx | 38 +++++----- src/businesslogic/types/lecture.ts | 1 + src/components/RightBar/LectureCard/index.tsx | 2 +- src/components/RightBar/index.tsx | 69 ++++++++++--------- src/components/TopBar/Results/index.tsx | 46 ++++++++++--- 5 files changed, 97 insertions(+), 59 deletions(-) diff --git a/src/businesslogic/LecturesProvider.tsx b/src/businesslogic/LecturesProvider.tsx index 3b4309a..09777f2 100644 --- a/src/businesslogic/LecturesProvider.tsx +++ b/src/businesslogic/LecturesProvider.tsx @@ -1,24 +1,28 @@ import React, { useState } from "react"; -import { Lecture } from "./mockData/lectures"; +import { lectures } from "./mockData/lectures"; +import { Lecture } from "./types/lecture"; interface ILectureContext { - lectures: Array - updateLectures: (lectures: Lecture) => void + lectures: Array; + updateLectures: (lectures: Lecture) => void; } -export const LecturesContext = React.createContext({lectures: Array(), updateLectures: (lectures: Lecture) => {}}); +export const LecturesContext = React.createContext({ + lectures: Array(), + updateLectures: (lectures: Lecture) => {}, +}); -export const LecturesProvider : React.FC = (props) => { +export const LecturesProvider: React.FC = (props) => { + const [lectures, setLectures] = useState>([]); - const [lectures, setLectures] = useState>([]); - - const updateLectures = (lecture : Lecture) => { setLectures([...lectures, lecture])} - - return ( - - {props.children} - - ); - - -} + const updateLectures = (lecture: Lecture) => { + setLectures([...lectures, lecture]); + }; + return ( + + {props.children} + + ); +}; diff --git a/src/businesslogic/types/lecture.ts b/src/businesslogic/types/lecture.ts index ef86640..604f44c 100644 --- a/src/businesslogic/types/lecture.ts +++ b/src/businesslogic/types/lecture.ts @@ -1,6 +1,7 @@ import { Group } from "./group"; export interface Lecture { + id?: number; name: string; groups: Array; } diff --git a/src/components/RightBar/LectureCard/index.tsx b/src/components/RightBar/LectureCard/index.tsx index a221a15..d18335f 100644 --- a/src/components/RightBar/LectureCard/index.tsx +++ b/src/components/RightBar/LectureCard/index.tsx @@ -2,7 +2,7 @@ import React from "react"; import "./index.scss"; import Collapse from "@material-ui/core/Collapse"; import ExpandIcon from "./expand.png"; -import { Lecture } from "../../../businesslogic/mockData/lectures"; +import { Lecture } from "../../../businesslogic/types/lecture"; interface LectureCardProps { onGroupMouseOver: (id: string, name: string) => void; diff --git a/src/components/RightBar/index.tsx b/src/components/RightBar/index.tsx index 29a9fee..07e627d 100644 --- a/src/components/RightBar/index.tsx +++ b/src/components/RightBar/index.tsx @@ -1,46 +1,51 @@ import React, { useState, useContext } from "react"; import "./index.scss"; -import { Lecture } from "../../businesslogic/mockData/lectures"; +import { Lecture } from "../../businesslogic/types/lecture"; import LectureCard from "./LectureCard"; import { LecturesContext } from "../../businesslogic/LecturesProvider"; interface RightBarProps { - onGroupMouseOver: (id: string, name: string) => void; - onGroupClick: (id: string, name: string) => void; - lectures: Array; + onGroupMouseOver: (id: string, name: string) => void; + onGroupClick: (id: string, name: string) => void; + lectures: Array; } -export default function RightBar({ lectures, onGroupMouseOver, onGroupClick }: RightBarProps) { - const [selectedCardId, setSelectedCardId] = useState(null); +export default function RightBar({ + lectures, + onGroupMouseOver, + onGroupClick, +}: RightBarProps) { + const [selectedCardId, setSelectedCardId] = useState(null); - const lecturesContext = useContext(LecturesContext); + const lecturesContext = useContext(LecturesContext); + const onCardClick = (e: React.MouseEvent) => { + const target = e.currentTarget as HTMLElement; + selectedCardId === target.id + ? setSelectedCardId(null) + : setSelectedCardId(target.id); + }; - const onCardClick = (e: React.MouseEvent) => { - const target = e.currentTarget as HTMLElement; - selectedCardId === target.id ? setSelectedCardId(null) : setSelectedCardId(target.id); - }; - - return ( -
- {/* + return ( +
+ {/* {(context) =>

{JSON.stringify((context as BuisnessProvided).states.user?.ticket)}

}
*/} -
- Hubert Wrzesiński

- Semestr zimowy 2020/2021 -
- {lecturesContext.lectures.map((lecture, index) => ( - - ))} -
- ); +
+ Hubert Wrzesiński

+ Semestr zimowy 2020/2021 +
+ {lecturesContext.lectures.map((lecture, index) => ( + + ))} +
+ ); } diff --git a/src/components/TopBar/Results/index.tsx b/src/components/TopBar/Results/index.tsx index c5a99a7..06960ed 100644 --- a/src/components/TopBar/Results/index.tsx +++ b/src/components/TopBar/Results/index.tsx @@ -1,15 +1,23 @@ import React, { useState, useContext, useEffect } from "react"; import axios from "axios"; -import { Input } from "@material-ui/core"; +import { Input, Grow } from "@material-ui/core"; import "./index.scss"; import ClickAwayListener from "@material-ui/core/ClickAwayListener"; import { LecturesContext } from "../../../businesslogic/LecturesProvider"; import { Lecture } from "../../../businesslogic/types/lecture"; -import { LectureInit } from "../../../businesslogic/types/lectureInit"; +import { Group } from "../../../businesslogic/types/group"; + +interface LectureData { + name: string; + id: number; +} export const Results: React.FC = () => { const [input, setInput] = useState(""); - const [lecturesData, setLecturesData] = useState>([]); + const [lecturesData, setLecturesData] = useState>([]); + const [filteredLecturesData, setFilteredLecturesData] = useState< + Array + >([]); const [open, setOpen] = React.useState(false); const lecturesContext = useContext(LecturesContext); @@ -42,16 +50,15 @@ export const Results: React.FC = () => { useEffect(() => { const filterLectures = (value: string) => { - const zmienna = lecturesData.filter((lecture) => + const filteredLectures = lecturesData.filter((lecture) => lecture.name.toLowerCase().includes(value.toLowerCase()) ); - console.log(zmienna); - return zmienna; + setFilteredLecturesData(filteredLectures); }; filterLectures(input); }, [input]); - const getLecturesById = async (id: string): Promise => { + const getLecturesById = async (id: string) => { const { data } = await axios.get( `http://localhost:1287/getClassesByCourseId?id=${id}` ); @@ -74,7 +81,28 @@ export const Results: React.FC = () => { const target = e.currentTarget as HTMLElement; const id = target.id; const result = await getLecturesById(id); - lecturesContext.updateLectures(result); + let groups: Array = []; + let lecture = { groups: groups } as Lecture; + lecture.id = result[0].course.id; + lecture.name = result[0].course.name; + for (let i = 0; i < result.length; i++) { + let group = {} as Group; + group.id = result[i].id; + group.day = result[i].day; + group.time = result[i].time; + group.lecturer = + result[i].lecturer.title + + " " + + result[i].lecturer.name + + " " + + result[i].lecturer.surname; + group.room = result[i].room; + lecture.groups.push(group); + } + console.log(result); + console.log(result[0].course.name); + + lecturesContext.updateLectures(lecture); setOpen(false); }; @@ -91,7 +119,7 @@ export const Results: React.FC = () => { /> {open ? (
- {lecturesData.map((lecture, index) => ( + {filteredLecturesData.map((lecture, index) => (