Refactor
This commit is contained in:
parent
f95c8d450d
commit
c194bf1ee2
@ -4,7 +4,7 @@ import Transfer from "./components/Transfer/";
|
|||||||
import "./App.scss";
|
import "./App.scss";
|
||||||
import {Scheduler} from "./components/Scheduler";
|
import {Scheduler} from "./components/Scheduler";
|
||||||
import RightBar from "./components/RightBar";
|
import RightBar from "./components/RightBar";
|
||||||
import { lectures } from "./lectures";
|
import { lectures } from "./businesslogic/mockData/lectures";
|
||||||
|
|
||||||
import BusinessLogicContext from "./businesslogic/BusinessLogicContext";
|
import BusinessLogicContext from "./businesslogic/BusinessLogicContext";
|
||||||
import { BuisnessProvided } from "./businesslogic/BusinessLogicProvider";
|
import { BuisnessProvided } from "./businesslogic/BusinessLogicProvider";
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import BusinessLogicContext from "./BusinessLogicContext";
|
import BusinessLogicContext from "./BusinessLogicContext";
|
||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { User } from "./models/user";
|
import { User } from "./types/user";
|
||||||
|
|
||||||
export interface BuisnessProvided {
|
export interface BuisnessProvided {
|
||||||
states: BusinessState;
|
states: BusinessState;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { Lecture } from "../lectures";
|
import { Lecture } from "./mockData/lectures";
|
||||||
|
|
||||||
interface ILectureContext {
|
interface ILectureContext {
|
||||||
lectures: Array<Lecture>
|
lectures: Array<Lecture>
|
||||||
|
42
src/businesslogic/mockData/lectures.ts
Normal file
42
src/businesslogic/mockData/lectures.ts
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import { Lecture } from "../types/lecture";
|
||||||
|
|
||||||
|
export const lectures: Array<Lecture> = [
|
||||||
|
{
|
||||||
|
name: "E-gospodarka - narzędzia i bezpieczeństwo",
|
||||||
|
groups: [
|
||||||
|
{
|
||||||
|
id: "1CB",
|
||||||
|
day: "Pn",
|
||||||
|
time: "10:00",
|
||||||
|
lecturer: "dr inż. Michał Ren",
|
||||||
|
room: "A2-01",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "1XD",
|
||||||
|
day: "Wt",
|
||||||
|
time: "12:00",
|
||||||
|
lecturer: "dr inż. Michał Ren",
|
||||||
|
room: "A3-01",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Statystyka",
|
||||||
|
groups: [
|
||||||
|
{
|
||||||
|
id: "2CB",
|
||||||
|
day: "Pn",
|
||||||
|
time: "10:00",
|
||||||
|
lecturer: "dr inż. Michał Ren",
|
||||||
|
room: "A2-01",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "2XD",
|
||||||
|
day: "Wt",
|
||||||
|
time: "12:00",
|
||||||
|
lecturer: "dr inż. Michał Ren",
|
||||||
|
room: "A3-01",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
7
src/businesslogic/types/group.ts
Normal file
7
src/businesslogic/types/group.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export interface Group {
|
||||||
|
id: string;
|
||||||
|
day: string;
|
||||||
|
time: string;
|
||||||
|
lecturer: string;
|
||||||
|
room: string;
|
||||||
|
}
|
6
src/businesslogic/types/lecture.ts
Normal file
6
src/businesslogic/types/lecture.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { Group } from "./group";
|
||||||
|
|
||||||
|
export interface Lecture {
|
||||||
|
name: string;
|
||||||
|
groups: Array<Group>;
|
||||||
|
}
|
4
src/businesslogic/types/lectureInit.ts
Normal file
4
src/businesslogic/types/lectureInit.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export interface LectureInit {
|
||||||
|
name: string;
|
||||||
|
id: number;
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
export type User = {
|
export interface User {
|
||||||
name?: string;
|
name?: string;
|
||||||
surname?: string;
|
surname?: string;
|
||||||
ticket: string | null;
|
ticket: string | null;
|
@ -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 "../../../lectures";
|
import { Lecture } from "../../../businesslogic/mockData/lectures";
|
||||||
|
|
||||||
interface LectureCardProps {
|
interface LectureCardProps {
|
||||||
onGroupMouseOver: (id: string, name: string) => void;
|
onGroupMouseOver: (id: string, name: string) => void;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import React, { useState, useContext } from "react";
|
import React, { useState, useContext } from "react";
|
||||||
import "./index.scss";
|
import "./index.scss";
|
||||||
import { Lecture } from "../../lectures";
|
import { Lecture } from "../../businesslogic/mockData/lectures";
|
||||||
import LectureCard from "./LectureCard";
|
import LectureCard from "./LectureCard";
|
||||||
import { LecturesContext } from "../../businesslogic/LecturesProvider";
|
import { LecturesContext } from "../../businesslogic/LecturesProvider";
|
||||||
|
|
||||||
|
@ -1,86 +1,75 @@
|
|||||||
import React, { useState, useContext } 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 } 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, Group } from "../../../lectures";
|
import {LectureInit} from "../../../businesslogic/types/lectureInit";
|
||||||
import { EDEADLK } from "constants";
|
|
||||||
|
|
||||||
interface data {
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
sym: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const Results: React.FC = () => {
|
export const Results: React.FC = () => {
|
||||||
const [input, setInput] = useState<string>("");
|
const [input, setInput] = useState<string>("");
|
||||||
const [data, setData] = useState<Array<data>>([]);
|
const [lecturesData, setLecturesData] = useState<Array<LectureInit>>([]);
|
||||||
const [open, setOpen] = React.useState(false);
|
const [open, setOpen] = React.useState(false);
|
||||||
|
|
||||||
const lecturesContext = useContext(LecturesContext);
|
const lecturesContext = useContext(LecturesContext);
|
||||||
|
|
||||||
|
//fetch lectures ids and lectures names
|
||||||
|
// useEffect(() => {
|
||||||
|
// const fetchData = async () => {
|
||||||
|
// const {lecturesData } = await axios.get(
|
||||||
|
// `http://localhost:1287/getCourses?name=""`
|
||||||
|
// );
|
||||||
|
// setLecturesData(lecturesData);
|
||||||
|
// };
|
||||||
|
// fetchData();
|
||||||
|
// }, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchData = async () => {
|
||||||
|
const { data } = await axios.get(
|
||||||
|
`http://localhost:1287/getCourses?name=""`
|
||||||
|
);
|
||||||
|
const lecturesData = data.map((data: { name: any; id: any; })=> {name: data.name, id: data.id})
|
||||||
|
|
||||||
|
setLecturesData(lecturesData);
|
||||||
|
};
|
||||||
|
fetchData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const filterLectures = (value: string) => {
|
||||||
|
return lecturesData.filter((lecture) => lecture.name.includes(value));
|
||||||
|
};
|
||||||
|
filterLectures(input);
|
||||||
|
}, [input]);
|
||||||
|
|
||||||
|
const getLecturesById = async (id: string): Promise<Lecture> => {
|
||||||
|
const { data } = await axios.get(
|
||||||
|
`http://localhost:1287/getClassesByCourseId?id=${id}`
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setInput(event.target.value);
|
setInput(event.target.value);
|
||||||
//query should be updated on backend to not accept empty string
|
};
|
||||||
if (event.target.value !== "") {
|
|
||||||
console.log("Jeste w okej")
|
|
||||||
search(event.target.value);
|
|
||||||
} else {
|
|
||||||
console.log("Jeste w dupuie")
|
|
||||||
search("xxxxxxxxxxxxxxx");
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const search = (text: string) => {
|
|
||||||
axios
|
|
||||||
.get(`http://localhost:1287/getCourses?name=${text}`)
|
|
||||||
.then((response) => {
|
|
||||||
const names = lecturesContext.lectures.map(lecture => lecture.name);
|
|
||||||
console.log(`Names: ${names}`)
|
|
||||||
const filteredData = response.data.filter((el : any) => !names.includes(el.name));
|
|
||||||
console.log("D")
|
|
||||||
setData(filteredData)
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
console.log("OPWENEE")
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClickAway = () => {
|
const handleClickAway = () => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onLectureClick = (e: React.MouseEvent) => {
|
const onLectureClick = async (e: React.MouseEvent) => {
|
||||||
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 lecture = {name: "", groups: []} as Lecture;
|
lecturesContext.updateLectures(result);
|
||||||
|
|
||||||
axios
|
|
||||||
.get(`http://localhost:1287/getClassesByCourseId?id=${id}`)
|
|
||||||
.then((response) => {
|
|
||||||
for(let data of response.data){
|
|
||||||
let group = {} as Group;
|
|
||||||
lecture.name = data.course.name;
|
|
||||||
group.id = data.id;
|
|
||||||
group.day = data.day;
|
|
||||||
group.time = data.time;
|
|
||||||
group.lecturer = `${data.lecturer.title} ${data.lecturer.name} ${data.lecturer.surname}`;
|
|
||||||
group.room = data.room.trim();
|
|
||||||
lecture.groups.push(group);
|
|
||||||
lecturesContext.updateLectures(lecture);
|
|
||||||
}
|
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
}).then(()=>{search(input)});
|
};
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ClickAwayListener onClickAway={handleClickAway}>
|
<ClickAwayListener onClickAway={handleClickAway}>
|
||||||
@ -95,8 +84,13 @@ export const Results: React.FC = () => {
|
|||||||
/>
|
/>
|
||||||
{open ? (
|
{open ? (
|
||||||
<div className="dropdown">
|
<div className="dropdown">
|
||||||
{data.map((lecture, index) => (
|
{lecturesData.map((lecture, index) => (
|
||||||
<div className="lecture" key={index} id={String(lecture.id)} onClick={onLectureClick}>
|
<div
|
||||||
|
className="lecture"
|
||||||
|
key={index}
|
||||||
|
id={String(lecture.id)}
|
||||||
|
onClick={onLectureClick}
|
||||||
|
>
|
||||||
<p>{lecture.name} </p>
|
<p>{lecture.name} </p>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
@ -106,4 +100,3 @@ export const Results: React.FC = () => {
|
|||||||
</ClickAwayListener>
|
</ClickAwayListener>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
export interface Lecture {
|
|
||||||
name: string;
|
|
||||||
groups: Array<Group>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Group {
|
|
||||||
id: string;
|
|
||||||
day: string;
|
|
||||||
time: string;
|
|
||||||
lecturer: string;
|
|
||||||
room: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const lectures: Array<Lecture> = [
|
|
||||||
{
|
|
||||||
name: "E-gospodarka - narzędzia i bezpieczeństwo",
|
|
||||||
groups: [
|
|
||||||
{
|
|
||||||
id: "1CB",
|
|
||||||
day: "Pn",
|
|
||||||
time: "10:00",
|
|
||||||
lecturer: "dr inż. Michał Ren",
|
|
||||||
room: "A2-01",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "1XD",
|
|
||||||
day: "Wt",
|
|
||||||
time: "12:00",
|
|
||||||
lecturer: "dr inż. Michał Ren",
|
|
||||||
room: "A3-01",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Statystyka",
|
|
||||||
groups: [
|
|
||||||
{
|
|
||||||
id: "2CB",
|
|
||||||
day: "Pn",
|
|
||||||
time: "10:00",
|
|
||||||
lecturer: "dr inż. Michał Ren",
|
|
||||||
room: "A2-01",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "2XD",
|
|
||||||
day: "Wt",
|
|
||||||
time: "12:00",
|
|
||||||
lecturer: "dr inż. Michał Ren",
|
|
||||||
room: "A3-01",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
Loading…
Reference in New Issue
Block a user