Dej te endpointy
This commit is contained in:
parent
34d7f9a14e
commit
bef314120a
@ -1,24 +1,28 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { Lecture } from "./mockData/lectures";
|
import { lectures } from "./mockData/lectures";
|
||||||
|
import { Lecture } from "./types/lecture";
|
||||||
|
|
||||||
interface ILectureContext {
|
interface ILectureContext {
|
||||||
lectures: Array<Lecture>
|
lectures: Array<Lecture>;
|
||||||
updateLectures: (lectures: Lecture) => void
|
updateLectures: (lectures: Lecture) => void;
|
||||||
}
|
}
|
||||||
export const LecturesContext = React.createContext({lectures: Array<Lecture>(), updateLectures: (lectures: Lecture) => {}});
|
export const LecturesContext = React.createContext({
|
||||||
|
lectures: Array<Lecture>(),
|
||||||
|
updateLectures: (lectures: Lecture) => {},
|
||||||
|
});
|
||||||
|
|
||||||
export const LecturesProvider : React.FC = (props) => {
|
export const LecturesProvider: React.FC = (props) => {
|
||||||
|
const [lectures, setLectures] = useState<Array<Lecture>>([]);
|
||||||
|
|
||||||
const [lectures, setLectures] = useState<Array<Lecture>>([]);
|
const updateLectures = (lecture: Lecture) => {
|
||||||
|
setLectures([...lectures, lecture]);
|
||||||
const updateLectures = (lecture : Lecture) => { setLectures([...lectures, lecture])}
|
};
|
||||||
|
|
||||||
return (
|
|
||||||
<LecturesContext.Provider value={{lectures: lectures, updateLectures : updateLectures}}>
|
|
||||||
{props.children}
|
|
||||||
</LecturesContext.Provider>
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<LecturesContext.Provider
|
||||||
|
value={{ lectures: lectures, updateLectures: updateLectures }}
|
||||||
|
>
|
||||||
|
{props.children}
|
||||||
|
</LecturesContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Group } from "./group";
|
import { Group } from "./group";
|
||||||
|
|
||||||
export interface Lecture {
|
export interface Lecture {
|
||||||
|
id?: number;
|
||||||
name: string;
|
name: string;
|
||||||
groups: Array<Group>;
|
groups: Array<Group>;
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import React from "react";
|
|||||||
import "./index.scss";
|
import "./index.scss";
|
||||||
import Collapse from "@material-ui/core/Collapse";
|
import Collapse from "@material-ui/core/Collapse";
|
||||||
import ExpandIcon from "./expand.png";
|
import ExpandIcon from "./expand.png";
|
||||||
import { Lecture } from "../../../businesslogic/mockData/lectures";
|
import { Lecture } from "../../../businesslogic/types/lecture";
|
||||||
|
|
||||||
interface LectureCardProps {
|
interface LectureCardProps {
|
||||||
onGroupMouseOver: (id: string, name: string) => void;
|
onGroupMouseOver: (id: string, name: string) => void;
|
||||||
|
@ -1,46 +1,51 @@
|
|||||||
import React, { useState, useContext } from "react";
|
import React, { useState, useContext } from "react";
|
||||||
import "./index.scss";
|
import "./index.scss";
|
||||||
import { Lecture } from "../../businesslogic/mockData/lectures";
|
import { Lecture } from "../../businesslogic/types/lecture";
|
||||||
import LectureCard from "./LectureCard";
|
import LectureCard from "./LectureCard";
|
||||||
import { LecturesContext } from "../../businesslogic/LecturesProvider";
|
import { LecturesContext } from "../../businesslogic/LecturesProvider";
|
||||||
|
|
||||||
interface RightBarProps {
|
interface RightBarProps {
|
||||||
onGroupMouseOver: (id: string, name: string) => void;
|
onGroupMouseOver: (id: string, name: string) => void;
|
||||||
onGroupClick: (id: string, name: string) => void;
|
onGroupClick: (id: string, name: string) => void;
|
||||||
lectures: Array<Lecture>;
|
lectures: Array<Lecture>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function RightBar({ lectures, onGroupMouseOver, onGroupClick }: RightBarProps) {
|
export default function RightBar({
|
||||||
const [selectedCardId, setSelectedCardId] = useState<string | null>(null);
|
lectures,
|
||||||
|
onGroupMouseOver,
|
||||||
|
onGroupClick,
|
||||||
|
}: RightBarProps) {
|
||||||
|
const [selectedCardId, setSelectedCardId] = useState<string | null>(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) => {
|
return (
|
||||||
const target = e.currentTarget as HTMLElement;
|
<div className="right-bar">
|
||||||
selectedCardId === target.id ? setSelectedCardId(null) : setSelectedCardId(target.id);
|
{/* <BusinessLogicContext.Consumer>
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="right-bar">
|
|
||||||
{/* <BusinessLogicContext.Consumer>
|
|
||||||
{(context) => <p>{JSON.stringify((context as BuisnessProvided).states.user?.ticket)}</p>}
|
{(context) => <p>{JSON.stringify((context as BuisnessProvided).states.user?.ticket)}</p>}
|
||||||
</BusinessLogicContext.Consumer> */}
|
</BusinessLogicContext.Consumer> */}
|
||||||
<div className="right-bar__text">
|
<div className="right-bar__text">
|
||||||
Hubert Wrzesiński<br></br>
|
Hubert Wrzesiński<br></br>
|
||||||
Semestr zimowy 2020/2021
|
Semestr zimowy 2020/2021
|
||||||
</div>
|
</div>
|
||||||
{lecturesContext.lectures.map((lecture, index) => (
|
{lecturesContext.lectures.map((lecture, index) => (
|
||||||
<LectureCard
|
<LectureCard
|
||||||
lecture={lecture}
|
lecture={lecture}
|
||||||
key={index}
|
key={index}
|
||||||
id={index.toString()}
|
id={index.toString()}
|
||||||
onGroupMouseOver={onGroupMouseOver}
|
onGroupMouseOver={onGroupMouseOver}
|
||||||
onGroupClick={onGroupClick}
|
onGroupClick={onGroupClick}
|
||||||
onCardClick={onCardClick}
|
onCardClick={onCardClick}
|
||||||
isSelected={selectedCardId === index.toString()}
|
isSelected={selectedCardId === index.toString()}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,23 @@
|
|||||||
import React, { useState, useContext, useEffect } from "react";
|
import React, { useState, useContext, useEffect } from "react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { Input } from "@material-ui/core";
|
import { Input, Grow } from "@material-ui/core";
|
||||||
import "./index.scss";
|
import "./index.scss";
|
||||||
import ClickAwayListener from "@material-ui/core/ClickAwayListener";
|
import ClickAwayListener from "@material-ui/core/ClickAwayListener";
|
||||||
import { LecturesContext } from "../../../businesslogic/LecturesProvider";
|
import { LecturesContext } from "../../../businesslogic/LecturesProvider";
|
||||||
import { Lecture } from "../../../businesslogic/types/lecture";
|
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 = () => {
|
export const Results: React.FC = () => {
|
||||||
const [input, setInput] = useState<string>("");
|
const [input, setInput] = useState<string>("");
|
||||||
const [lecturesData, setLecturesData] = useState<Array<LectureInit>>([]);
|
const [lecturesData, setLecturesData] = useState<Array<LectureData>>([]);
|
||||||
|
const [filteredLecturesData, setFilteredLecturesData] = useState<
|
||||||
|
Array<LectureData>
|
||||||
|
>([]);
|
||||||
const [open, setOpen] = React.useState(false);
|
const [open, setOpen] = React.useState(false);
|
||||||
|
|
||||||
const lecturesContext = useContext(LecturesContext);
|
const lecturesContext = useContext(LecturesContext);
|
||||||
@ -42,16 +50,15 @@ export const Results: React.FC = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const filterLectures = (value: string) => {
|
const filterLectures = (value: string) => {
|
||||||
const zmienna = lecturesData.filter((lecture) =>
|
const filteredLectures = lecturesData.filter((lecture) =>
|
||||||
lecture.name.toLowerCase().includes(value.toLowerCase())
|
lecture.name.toLowerCase().includes(value.toLowerCase())
|
||||||
);
|
);
|
||||||
console.log(zmienna);
|
setFilteredLecturesData(filteredLectures);
|
||||||
return zmienna;
|
|
||||||
};
|
};
|
||||||
filterLectures(input);
|
filterLectures(input);
|
||||||
}, [input]);
|
}, [input]);
|
||||||
|
|
||||||
const getLecturesById = async (id: string): Promise<Lecture> => {
|
const getLecturesById = async (id: string) => {
|
||||||
const { data } = await axios.get(
|
const { data } = await axios.get(
|
||||||
`http://localhost:1287/getClassesByCourseId?id=${id}`
|
`http://localhost:1287/getClassesByCourseId?id=${id}`
|
||||||
);
|
);
|
||||||
@ -74,7 +81,28 @@ export const Results: React.FC = () => {
|
|||||||
const target = e.currentTarget as HTMLElement;
|
const target = e.currentTarget as HTMLElement;
|
||||||
const id = target.id;
|
const id = target.id;
|
||||||
const result = await getLecturesById(id);
|
const result = await getLecturesById(id);
|
||||||
lecturesContext.updateLectures(result);
|
let groups: Array<Group> = [];
|
||||||
|
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);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -91,7 +119,7 @@ export const Results: React.FC = () => {
|
|||||||
/>
|
/>
|
||||||
{open ? (
|
{open ? (
|
||||||
<div className="dropdown">
|
<div className="dropdown">
|
||||||
{lecturesData.map((lecture, index) => (
|
{filteredLecturesData.map((lecture, index) => (
|
||||||
<div
|
<div
|
||||||
className="lecture"
|
className="lecture"
|
||||||
key={index}
|
key={index}
|
||||||
|
Loading…
Reference in New Issue
Block a user