not sorted basket

This commit is contained in:
wrzesinski-hubert 2020-11-20 21:20:32 +01:00
parent 47bfd9572c
commit 9a88736584
3 changed files with 15 additions and 3 deletions

View File

@ -54,6 +54,8 @@ export const Dropdown = forwardRef(({ open, input, handleCloseDropdown }: Dropdo
const { courses, basket, addToBasket } = useContext(coursesContext)!; const { courses, basket, addToBasket } = useContext(coursesContext)!;
const sortedCourses = courses.sort((a, b) => (a.name > b.name ? 1 : -1));
useEffect(() => { useEffect(() => {
console.log('wut'); console.log('wut');
}, [open, input, handleCloseDropdown]); }, [open, input, handleCloseDropdown]);
@ -69,7 +71,7 @@ export const Dropdown = forwardRef(({ open, input, handleCloseDropdown }: Dropdo
useEffect(() => { useEffect(() => {
const filterCourses = (input: string) => { const filterCourses = (input: string) => {
const choosenCoursesNames = basket.map(({ name }) => name.trim()); const choosenCoursesNames = basket.map(({ name }) => name.trim());
const filteredCourses = courses.filter( const filteredCourses = sortedCourses.filter(
({ name }) => ({ name }) =>
name name
.toLowerCase() .toLowerCase()

View File

@ -50,7 +50,18 @@ export const Rightbar = () => {
const getBasketGroups = () => { const getBasketGroups = () => {
const names = basket.map(({ name }) => name); const names = basket.map(({ name }) => name);
return courses.filter(({ name }) => names.includes(name));
const list = []
for (const basketName of names){
const course = courses.find(({name})=>basketName===name)!
list.push(course);
}
console.log("asdasdsa1", list);
console.log("asdasdsa2", courses.filter(({ name }) => names.includes(name)));
return list;
}; };
const filteredCourses = getBasketGroups(); const filteredCourses = getBasketGroups();

View File

@ -125,7 +125,6 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
const { data: courses } = await axios.get<Array<Course>>( const { data: courses } = await axios.get<Array<Course>>(
`${process.env.REACT_APP_API_URL}/api/v1/courses/getCoursesWithGroups`, `${process.env.REACT_APP_API_URL}/api/v1/courses/getCoursesWithGroups`,
); );
courses.sort((a, b) => (a.name > b.name ? 1 : -1));
setCourses(courses); setCourses(courses);
} catch (e) { } catch (e) {
console.log(e); console.log(e);