mocked saveBasket to backend

This commit is contained in:
Maciek Głowacki 2020-10-01 20:06:38 +02:00
parent d6aa58fd34
commit ffce67ab42
2 changed files with 15 additions and 9 deletions

View File

@ -42,10 +42,13 @@ const SaveButton = styled.div`
height: 40px;
background-color: red;
margin-bottom: 10px;
&:hover {
color: #d3d3d3;
}
`;
export const Rightbar = () => {
const { courses, basket } = useContext(coursesContext)!;
const { courses, basket, saveBasket } = useContext(coursesContext)!;
const getBasketGroups = () => {
const names = basket.map(({ name }) => name);
@ -62,7 +65,7 @@ export const Rightbar = () => {
Hubert Wrzesiński<br></br>
Semestr zimowy 2020/2021
</p>
<SaveButton>SAVE</SaveButton>
<SaveButton onClick={saveBasket}>SAVE</SaveButton>
</RightbarTextStyled>
{filteredCourses.map((course, index) => (
<CourseCard course={course} key={index} />

View File

@ -8,6 +8,7 @@ interface CourseContext {
addToBasket: (courses: Course) => void;
addGroup: (group: Group, id: number) => void;
deleteFromBasket: (id: number) => void;
saveBasket: () => void;
}
export const coursesContext = createContext<CourseContext | null>(null);
@ -32,12 +33,14 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
const deleteFromBasket = (id: number) => setBasket(basket.filter((course) => course.id !== id));
useEffect(() => {
console.log('BASKET');
console.log(basket);
}, [basket]);
//immutability
const saveBasket = () => {
// try {
// axios.post(`${process.env.REACT_APP_API_URL}/api/v1/commisions/add`);
// } catch (e) {
// console.log(e);
// }
console.log('saving to basket');
};
const addGroup = (choosenGroup: Group, id: number) => {
const basketCourse = basket.filter((course) => course.id === id)[0];
@ -74,7 +77,7 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
}, []);
return (
<coursesContext.Provider value={{ courses, basket, addToBasket, addGroup, deleteFromBasket }}>
<coursesContext.Provider value={{ courses, basket, addToBasket, addGroup, deleteFromBasket, saveBasket }}>
{children}
</coursesContext.Provider>
);