Small refactor

This commit is contained in:
unknown 2020-07-24 17:01:35 +02:00
commit 34d7f9a14e

View File

@ -4,9 +4,9 @@ import { Input } 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";
export const Results: React.FC = () => {
const [input, setInput] = useState<string>("");
const [lecturesData, setLecturesData] = useState<Array<LectureInit>>([]);
@ -27,10 +27,13 @@ export const Results: React.FC = () => {
useEffect(() => {
const fetchData = async () => {
const { data } = await axios.get(
`http://localhost:1287/getCourses?name=""`
const results = await axios.get(`http://localhost:1287/getCourses?name=`);
const lecturesData = results.data.map(
(result: { id: number; name: string }) => ({
id: result.id,
name: result.name,
})
);
const lecturesData = data.map((data: { name: any; id: any; })=> {name: data.name, id: data.id})
setLecturesData(lecturesData);
};
@ -39,7 +42,11 @@ export const Results: React.FC = () => {
useEffect(() => {
const filterLectures = (value: string) => {
return lecturesData.filter((lecture) => lecture.name.includes(value));
const zmienna = lecturesData.filter((lecture) =>
lecture.name.toLowerCase().includes(value.toLowerCase())
);
console.log(zmienna);
return zmienna;
};
filterLectures(input);
}, [input]);