lots of changes

This commit is contained in:
wrzesinski-hubert 2020-12-10 21:26:09 +01:00
parent a3438586bd
commit b6121a5eee
9 changed files with 38 additions and 26 deletions

View File

@ -1,13 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<html lang="pl">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="https://plannaplan.pl/img/logo.svg" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
content="Aplikacja do zapisów na zajęcia"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
@ -23,7 +22,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>PlanNaPlan</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>

View File

@ -12,6 +12,7 @@ const LeftSide = styled.div`
flex: 1;
flex-direction: column;
background-color: white;
text-align:center;
`;
const Wrap = styled.div`

View File

@ -27,9 +27,9 @@ export const App = () => {
<Topbar handleTransfer={handleTransfer} />
<Transfer isOpen={isOpenTransfer} handleClose={handleTransfer} />
<Wrapper>
{/* <Admin/> */}
<Scheduler />
<Rightbar />
{sessionStorage.getItem('userPrivilage')=== "STUDENT" ? <><Scheduler />
<Rightbar /></>: <Admin/>}
</Wrapper>
</>
);

View File

@ -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<FlexItemProps>`
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', '')}
</FlexItem>
)}
{console.log("abisfdibuafsbuiafsbuifasbuibuiafsbuifasbuifsabuiasf",group)}
<FlexItem style={{ justifyContent: 'center', margin: '0 50px' }}>
<span>{/*group.time*/}</span> <span> Sala: {group.room}</span>
<span> {createClassTime(group.time)[0] + " - " + createClassTime(group.time)[1]} {/* Sala: {group.room} */}</span>
</FlexItem>
</FlexboxWrapper>
</ClassGroupStyled>

View File

@ -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<Array<Course>>([]);
const [filteredUsers, setFilteredUsers] = useState<Array<User>>([]);
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(() => {

View File

@ -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 (
<RightbarWrapper>
<SaveButton onClick={handleSave}>ZAPISZ</SaveButton>

View File

@ -162,7 +162,7 @@ export default function ({ handleTransfer }: TopbarProps) {
<FlexboxColumn>
<ClickAwayListener onClickAway={handleCloseDropdown}>
<Flexbox>
{/* <SelectMenu changeSelectedOption={changeSelectedOption} selectedOption={selectedOption} changeDropdownOpen={setOpen}/> */}
{sessionStorage.getItem('userPrivilage')=== "STUDENT" ? (<div></div>): <SelectMenu changeSelectedOption={changeSelectedOption} selectedOption={selectedOption} changeDropdownOpen={setOpen}/>}
<InputWrapper>
<Input
placeholder={`Wyszukaj ${selectedOption === "studenci" ? "studentów..." : "przedmioty..."}`}

View File

@ -28,6 +28,7 @@ export const CASProvider = ({ children }: CASProviderProps) => {
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 = {

View File

@ -18,12 +18,14 @@ interface CourseContext {
courses: Array<Course>;
basket: Array<Basket>;
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<void>
getUserID: (userID: string) => Promise<void>
selectSchedulerEvents: () => Array<SchedulerEvent>;
selectBasketNames: () => Array<string>;
selectBasketCourses: () => Array<Course>;
@ -43,6 +45,7 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
//fetch courses with groups
const [courses, setCourses] = useState<Array<Course>>([]);
const [basket, setBasket] = useState<Array<Basket>>([]);
const [userekID, setUserID] = useState("");
const [hoveredGroup, setHoveredGroup] = useState<Group | undefined | null>(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 (
<coursesContext.Provider
value={{
userekID,
courses,
basket,
hoveredGroup,
@ -213,6 +222,7 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
selectBasketCourses,
selectBasketCourseGroups,
getUserTimetable,
getUserID,
}}
>
{children}