From b6121a5eee0ff896fdc8062d5ebcc414c19d215b Mon Sep 17 00:00:00 2001 From: wrzesinski-hubert Date: Thu, 10 Dec 2020 21:26:09 +0100 Subject: [PATCH] lots of changes --- public/index.html | 9 ++++----- src/components/Admin.tsx | 1 + src/components/App.tsx | 6 +++--- src/components/CourseCard.tsx | 11 +++++++---- src/components/Dropdown.tsx | 10 ++++------ src/components/Rightbar.tsx | 6 +++--- src/components/Topbar.tsx | 2 +- src/contexts/CASProvider.tsx | 1 + src/contexts/CoursesProvider.tsx | 18 ++++++++++++++---- 9 files changed, 38 insertions(+), 26 deletions(-) diff --git a/public/index.html b/public/index.html index 5f2ca52..69b1fe0 100644 --- a/public/index.html +++ b/public/index.html @@ -1,13 +1,12 @@ - + - - + - React App + PlanNaPlan diff --git a/src/components/Admin.tsx b/src/components/Admin.tsx index a647574..632a24a 100644 --- a/src/components/Admin.tsx +++ b/src/components/Admin.tsx @@ -12,6 +12,7 @@ const LeftSide = styled.div` flex: 1; flex-direction: column; background-color: white; + text-align:center; `; const Wrap = styled.div` diff --git a/src/components/App.tsx b/src/components/App.tsx index de05d54..4c8a82b 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -27,9 +27,9 @@ export const App = () => { - {/* */} - - + + {sessionStorage.getItem('userPrivilage')=== "STUDENT" ? <> + : } ); diff --git a/src/components/CourseCard.tsx b/src/components/CourseCard.tsx index fa26576..a381f29 100644 --- a/src/components/CourseCard.tsx +++ b/src/components/CourseCard.tsx @@ -7,6 +7,7 @@ import styled, { css } from 'styled-components'; import { makeStyles } from '@material-ui/core/styles'; import DeleteIcon from '@material-ui/icons/Delete'; import { useMemo } from 'react'; +import { createClassTime } from '../utils'; const CourseCardWrapper = styled.div` position: relative; @@ -20,7 +21,7 @@ const CourseCardWrapper = styled.div` border-radius: 10px; cursor: pointer; align-items: stretch; - box-shadow: 9px 9px 8px -2px rgba(0, 0, 0, 0.59); + box-shadow: 3px 3px 3px 0px rgba(0, 0, 0, 0.75); `; const TitleWrapper = styled.div` @@ -52,6 +53,7 @@ const ClassGroupStyled = styled.div` position: relative; padding-top: 1px; padding-bottom: 5px; + transition: background-color 0.4s ease; :hover { cursor: pointer; background-color: #9ed3ff; @@ -102,7 +104,7 @@ type FlexItemProps = { const FlexItem = styled.div` display: flex; font-size: 14px; - font-weight: 600; + font-weight: 500; ${({ justifyContent }) => justifyContent && css` @@ -141,7 +143,7 @@ export const CourseCard = ({ course }: CourseCardProps) => { selectBasketCourseGroups, changeHoveredGroup, } = useContext(coursesContext)!; - const [isSelected, setSelected] = useState(false); + const [isSelected, setSelected] = useState(true); const groups = [...course.lectures!, ...course.classes!]; const basketCourseGroups = useMemo(() => selectBasketCourseGroups(course.id), []); const [previous, setPrevious] = useState(basketCourseGroups); @@ -203,8 +205,9 @@ export const CourseCard = ({ course }: CourseCardProps) => { {group.lecturer.replace('UAM', '')} )} + {console.log("abisfdibuafsbuiafsbuifasbuibuiafsbuifasbuifsabuiasf",group)} - {/*group.time*/} Sala: {group.room} + {createClassTime(group.time)[0] + " - " + createClassTime(group.time)[1]} {/* Sala: {group.room} */} diff --git a/src/components/Dropdown.tsx b/src/components/Dropdown.tsx index 2efce4f..855dbe8 100644 --- a/src/components/Dropdown.tsx +++ b/src/components/Dropdown.tsx @@ -50,12 +50,13 @@ interface DropdownProps { } export const Dropdown = ({ open, input, handleCloseDropdown, selectedOption }: DropdownProps) => { - const { courses, selectBasketNames, addCourseToBasket,getUserTimetable } = useContext(coursesContext)!; + const { courses, selectBasketNames, addCourseToBasket, getUserID } = useContext(coursesContext)!; const { users } = useContext(usersContext)!; const basketNames = useMemo(() => selectBasketNames(), [selectBasketNames]); const [filteredCourses, setFilteredCourses] = useState>([]); const [filteredUsers, setFilteredUsers] = useState>([]); + const onCourseClick = (event: MouseEvent) => { const target = event.currentTarget; if (target.id && target.textContent) { @@ -67,11 +68,8 @@ export const Dropdown = ({ open, input, handleCloseDropdown, selectedOption }: D const onUserClick = (event: MouseEvent) => { const target = event.currentTarget; - if (target.id && target.textContent) { - console.log(target.id,target.textContent); - getUserTimetable(target.id); - handleCloseDropdown(); - } + getUserID(target.id); + handleCloseDropdown(); }; useEffect(() => { diff --git a/src/components/Rightbar.tsx b/src/components/Rightbar.tsx index 610def4..05c2cc3 100644 --- a/src/components/Rightbar.tsx +++ b/src/components/Rightbar.tsx @@ -44,14 +44,14 @@ const SaveButton = styled.div` background-color: #54c457; } - box-shadow: 0px 3px 3px 0px rgba(0, 0, 0, 0.24); + box-shadow: 3px 3px 3px 0px rgba(0, 0, 0, 0.75); `; export const Rightbar = () => { - const { selectBasketCourses, saveBasket } = useContext(coursesContext)!; + const { selectBasketCourses, saveBasket, userekID } = useContext(coursesContext)!; const basketCourses = selectBasketCourses(); - const handleSave = debounce(() => saveBasket(), 500); + const handleSave = debounce(() => saveBasket(userekID), 500); return ( ZAPISZ diff --git a/src/components/Topbar.tsx b/src/components/Topbar.tsx index 2115041..20c75e9 100644 --- a/src/components/Topbar.tsx +++ b/src/components/Topbar.tsx @@ -162,7 +162,7 @@ export default function ({ handleTransfer }: TopbarProps) { - {/* */} + {sessionStorage.getItem('userPrivilage')=== "STUDENT" ? (
): } { if (!sessionStorage.getItem('userToken')) { const { data: token } = await axiosInstance.get(`${process.env.REACT_APP_API_URL}/token?ticket=${ticket}`); sessionStorage.setItem('userToken', token.token); + sessionStorage.setItem('userPrivilage', token.authorityRole) } const tokenik:any = JSON.parse(sessionStorage.getItem('userToken')as string); const token: Token = { diff --git a/src/contexts/CoursesProvider.tsx b/src/contexts/CoursesProvider.tsx index 347df5d..4221f33 100644 --- a/src/contexts/CoursesProvider.tsx +++ b/src/contexts/CoursesProvider.tsx @@ -18,12 +18,14 @@ interface CourseContext { courses: Array; basket: Array; hoveredGroup: Group | undefined | null; + userekID:string; addCourseToBasket: (courses: Course) => void; changeHoveredGroup: (group: Group | null) => void; changeGroupInBasket: (group: Group, courseId: number) => void; restoreGroupInBasket: (restoreGroup: Group, courseId: number) => void; deleteFromBasket: (id: number) => void; - saveBasket: () => void; + saveBasket: (userID: string) => Promise + getUserID: (userID: string) => Promise selectSchedulerEvents: () => Array; selectBasketNames: () => Array; selectBasketCourses: () => Array; @@ -43,6 +45,7 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => { //fetch courses with groups const [courses, setCourses] = useState>([]); const [basket, setBasket] = useState>([]); + const [userekID, setUserID] = useState(""); const [hoveredGroup, setHoveredGroup] = useState(null); const selectBasketIds = () => { const classesIds = basket.map((course) => course?.classes?.id).filter((course) => course !== undefined); @@ -98,7 +101,12 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => { const deleteFromBasket = (id: number) => setBasket(basket.filter((course) => course.id !== id)); - const saveBasket = async () => { + const getUserID = async (userID:string) => { + setUserID(userID); + console.log("bjhkfbkjakbhjlfasbjkhlfabjklasfbjkbjkasfbjkasfl",userekID) + } + + const saveBasket = async (userID:string) => { const basketIds = selectBasketIds(); const action = (key: any) => ( <> @@ -111,7 +119,7 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => { ); try { - await axiosInstance.post(`${process.env.REACT_APP_API_URL}/api/v1/commisions/user`, JSON.stringify(basketIds)); + await axiosInstance.post(`${process.env.REACT_APP_API_URL}/api/v1/commisions/user/${userID}`, JSON.stringify(basketIds)); enqueueSnackbar('Plan został zapisany', { variant: 'success', action, @@ -193,12 +201,13 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => { setTimeout(() => { fetchCourses(); getNewestTimetable(); - }, 200); + }, 10); }, []); return ( { selectBasketCourses, selectBasketCourseGroups, getUserTimetable, + getUserID, }} > {children}