Merge pull request 'topbar changes:' (#37) from Admin into master

Reviewed-on: http://git.plannaplan.pl/y0rune/frontend/pulls/37
Reviewed-by: wrzesinski-hubert <wrzesinski.hubert@gmail.com>
This commit is contained in:
wrzesinski-hubert 2020-12-16 00:23:16 +01:00
commit da183bccfa
4 changed files with 31 additions and 14 deletions

View File

@ -59,7 +59,6 @@ const HistoryDiv = styled.div`
margin-left: 20px; margin-left: 20px;
border-radius: 5px; border-radius: 5px;
height: calc(100vh - 120px); height: calc(100vh - 120px);
background-color: red;
`; `;
const StatsDiv = styled.div` const StatsDiv = styled.div`
@ -68,7 +67,6 @@ const StatsDiv = styled.div`
margin-left: 20px; margin-left: 20px;
border-radius: 5px; border-radius: 5px;
height: calc(100vh - 120px); height: calc(100vh - 120px);
background-color: blue;
`; `;
const LogoWrapper = styled.div` const LogoWrapper = styled.div`

View File

@ -50,10 +50,8 @@ interface DropdownProps {
} }
export const Dropdown = ({ open, input, handleCloseDropdown, selectedOption }: DropdownProps) => { export const Dropdown = ({ open, input, handleCloseDropdown, selectedOption }: DropdownProps) => {
const { courses, selectBasketNames, addCourseToBasket, changeStudent } = useContext( const { courses, selectBasketNames, addCourseToBasket, changeStudent } = useContext(coursesContext)!;
coursesContext, const { students, changeSelectedStudent } = useContext(studentsContext)!;
)!;
const { students } = useContext(studentsContext)!;
const basketNames = useMemo(() => selectBasketNames(), [selectBasketNames]); const basketNames = useMemo(() => selectBasketNames(), [selectBasketNames]);
const [filteredCourses, setFilteredCourses] = useState<Array<Course>>([]); const [filteredCourses, setFilteredCourses] = useState<Array<Course>>([]);
const [filteredStudents, setFilteredStudents] = useState<Array<Student>>([]); const [filteredStudents, setFilteredStudents] = useState<Array<Student>>([]);
@ -69,7 +67,10 @@ export const Dropdown = ({ open, input, handleCloseDropdown, selectedOption }: D
const onUserClick = (event: MouseEvent) => { const onUserClick = (event: MouseEvent) => {
const target = event.currentTarget; const target = event.currentTarget;
console.log('target: ', target);
//to be moved to students provider
changeStudent(target.id); changeStudent(target.id);
changeSelectedStudent(Number(target.id));
handleCloseDropdown(); handleCloseDropdown();
}; };
@ -118,11 +119,9 @@ export const Dropdown = ({ open, input, handleCloseDropdown, selectedOption }: D
<> <>
{selectedOption === 'studenci' ? ( {selectedOption === 'studenci' ? (
<div> <div>
{filteredStudents.map(({ name, surname, id }, index) => ( {filteredStudents.map(({ email, id }, index) => (
<CourseContainer key={index} id={id.toString()} onClick={onUserClick}> <CourseContainer key={index} id={id.toString()} onClick={onUserClick}>
<p> <p>{email}</p>
{name} {surname}
</p>
</CourseContainer> </CourseContainer>
))} ))}
</div> </div>

View File

@ -1,4 +1,4 @@
import React, { useState, MouseEvent, ChangeEvent, useEffect, useCallback } from 'react'; import React, { useState, MouseEvent, ChangeEvent, useEffect, useCallback, useContext } from 'react';
import { ReactComponent as Close } from '../assets/close.svg'; import { ReactComponent as Close } from '../assets/close.svg';
import ProfileIcon from '../assets/account.svg'; import ProfileIcon from '../assets/account.svg';
import { Profile } from './Profile'; import { Profile } from './Profile';
@ -8,6 +8,7 @@ import EnglishIcon from '../assets/united-kingdom.svg';
import styled from 'styled-components/macro'; import styled from 'styled-components/macro';
import ClickAwayListener from 'react-click-away-listener'; import ClickAwayListener from 'react-click-away-listener';
import { SelectMenu } from './SelectMenu'; import { SelectMenu } from './SelectMenu';
import { studentsContext } from '../contexts/StudentsProvider';
const Topbar = styled.div` const Topbar = styled.div`
background-color: #e3e5ed; background-color: #e3e5ed;
@ -104,9 +105,10 @@ const CloseIcon = styled(Close)`
const IconWrapper = styled.div` const IconWrapper = styled.div`
display: flex; display: flex;
justify-content: flex-end;
align-items: center; align-items: center;
justify-content: flex-end;
width: 335px; width: 335px;
margin-right: 10px;
`; `;
const Icon = styled.img` const Icon = styled.img`
@ -122,13 +124,21 @@ export const Flexbox = styled.div`
display: flex; display: flex;
`; `;
export const SelectedStudent = styled.div`
width: 100%;
display: flex;
justify-content: center;
margin-right: 10px;
margin-left: 10px;
`;
interface TopbarProps { interface TopbarProps {
handleTransfer: (e: MouseEvent) => void; handleTransfer: (e: MouseEvent) => void;
} }
export default function ({ handleTransfer }: TopbarProps) { export default function ({ handleTransfer }: TopbarProps) {
const userPrivilige = localStorage.getItem('userPrivilige'); const userPrivilige = localStorage.getItem('userPrivilige');
const { selectedStudent } = useContext(studentsContext)!;
const [clearInput, setClearInput] = useState(false); const [clearInput, setClearInput] = useState(false);
const [isPolish, setIsPolish] = useState(false); const [isPolish, setIsPolish] = useState(false);
const [anchorEl, setAnchorEl] = useState<HTMLImageElement | null>(null); const [anchorEl, setAnchorEl] = useState<HTMLImageElement | null>(null);
@ -195,8 +205,9 @@ export default function ({ handleTransfer }: TopbarProps) {
/> />
</ClickAwayListener> </ClickAwayListener>
</FlexboxColumn> </FlexboxColumn>
<IconWrapper> <IconWrapper>
<SelectedStudent>{selectedStudent?.email.replace(/@st.amu.edu.pl/, '')}</SelectedStudent>
{/* <Text>Maciej Głowacki</Text> */} {/* <Text>Maciej Głowacki</Text> */}
{/* <Icon alt="transfer" src={Transfer} onClick={handleTransfer} /> */} {/* <Icon alt="transfer" src={Transfer} onClick={handleTransfer} /> */}
{/* <Icon alt="change_language" src={isPolish ? EnglishIcon : PolishIcon} onClick={onLangChange} /> */} {/* <Icon alt="change_language" src={isPolish ? EnglishIcon : PolishIcon} onClick={onLangChange} /> */}

View File

@ -5,6 +5,8 @@ import { CASContext } from './CASProvider';
interface StudentContext { interface StudentContext {
students: Array<Student>; students: Array<Student>;
selectedStudent: Student | null;
changeSelectedStudent: (studentId: number) => void;
} }
export const studentsContext = createContext<StudentContext | undefined>(undefined); export const studentsContext = createContext<StudentContext | undefined>(undefined);
@ -15,6 +17,7 @@ interface StudentsProviderProps {
export const StudentsProvider = ({ children }: StudentsProviderProps) => { export const StudentsProvider = ({ children }: StudentsProviderProps) => {
const [students, setStudents] = useState<Array<Student>>([]); const [students, setStudents] = useState<Array<Student>>([]);
const [selectedStudent, setSelectedStudent] = useState<Student | null>(null);
//not working currently //not working currently
const userPrivilige = localStorage.getItem('userPrivilige'); const userPrivilige = localStorage.getItem('userPrivilige');
@ -32,6 +35,10 @@ export const StudentsProvider = ({ children }: StudentsProviderProps) => {
} }
}; };
const changeSelectedStudent = (studentId: number) => {
setSelectedStudent(students.find((student) => student.id === studentId)!);
};
useEffect(() => { useEffect(() => {
setTimeout(() => { setTimeout(() => {
// user?.authorityRole === 'DEANERY' && // user?.authorityRole === 'DEANERY' &&
@ -42,7 +49,9 @@ export const StudentsProvider = ({ children }: StudentsProviderProps) => {
return ( return (
<studentsContext.Provider <studentsContext.Provider
value={{ value={{
selectedStudent,
students, students,
changeSelectedStudent,
}} }}
> >
{children} {children}