All files / src/components DeaneryPanel.tsx

55% Statements 11/20
0% Branches 0/8
0% Functions 0/3
55% Lines 11/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152                        1x                   1x             1x                     1x                                     1x               1x               1x                 1x           1x         1x                 1x                                                                                              
import React, { useState, MouseEvent,useContext } from 'react';
import styled from 'styled-components/macro';
import Plan from '../assets/plan.svg';
import History from '../assets/history.svg';
import StatisticsIcon from '../assets/statistics.svg';
import {Statistics} from './Statistics';
import { Scheduler } from './Scheduler';
import { Rightbar } from './Rightbar';
import { SchedulerHistory } from './SchedulerHistory';
import { coursesContext } from '../contexts/CoursesProvider';
import { SchedulerEvent } from '../types';
 
const LeftSide = styled.div`
  height: 100%;
  display: flex;
  flex: 1;
  flex-direction: column;
  background-color: white;
  text-align: center;
  border-radius: 5px;
`;
 
const Wrap = styled.div`
  display: flex;
  height: calc(100vh - 120px);
  background-color: #eceef4;
  width: 100%;
`;
 
const Wrapper = styled.div`
  flex: 12;
  display: flex;
  height: calc(100vh - 120px);
  background-color: #eceef4;
`;
 
interface LeftPanelElement {
  isCurrentTab: boolean;
}
 
const LeftPanelElement = styled.div<LeftPanelElement>`
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex: 1;
  //box-shadow: 0px 2px 2px 0px rgba(0, 0, 0, 0.75);
  padding: 20px;
  cursor: pointer;
  box-shadow: ${({ isCurrentTab }) => (isCurrentTab === true ? `inset 0px 0px 11px 0px rgba(0,0,0,0.30)` : '')};
  border-bottom: 1px solid #979797;
  :first-child {
    border-radius: 0px 5px 0px 0px;
  }
  :last-child {
    border-radius: 0px 0px 5px 0px;
  }
`;
 
const HistoryDiv = styled.div`
  flex: 1;
  display: flex;
  margin-left: 20px;
  border-radius: 5px;
  height: calc(100vh - 120px);
`;
 
const StatsDiv = styled.div`
  flex: 1;
  display: flex;
  margin-left: 20px;
  border-radius: 5px;
  height: calc(100vh - 120px);
`;
 
const LogoWrapper = styled.div`
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex: 2;
  margin-left: 10px;
`;
 
const Text = styled.div`
  font-family: 'Roboto', sans-serif;
  font-size: 5rem;
  user-select: none;
`;
 
const Logo = styled.img`
  width: 500px;
  height: 500px;
`;
 
const Icon = styled.img`
  width: 40px;
  margin: 5px;
`;
 
interface Deanery {
  schedulerEvents: Array<SchedulerEvent>;
}
 
export const DeaneryPanel = ({ schedulerEvents }: Deanery) => {
  const [currentTab, setCurrentTab] = useState<null | number>(1);
  const { getNewestStudentTimetable,userID } = useContext(coursesContext)!;
  const { selectHistorySchedulerEvents } = useContext(coursesContext)!;
  const schedulerHistoryEvents = selectHistorySchedulerEvents();
 
  const handleClick = (e: MouseEvent<HTMLDivElement>) => {
    setCurrentTab(Number(e.currentTarget.id));
    getNewestStudentTimetable(userID);
  };
 
  return (
    <Wrap>
      <LeftSide>
        <LeftPanelElement id={'1'} isCurrentTab={currentTab === 1} onClick={handleClick}>
          <Icon alt="profile" src={Plan} />
          Pokaż plan
        </LeftPanelElement>
        <LeftPanelElement id={'2'} isCurrentTab={currentTab === 2} onClick={handleClick}>
          <Icon alt="history" src={History} />
          Historia Zmian
        </LeftPanelElement>
        <LeftPanelElement id={'3'} isCurrentTab={currentTab === 3} onClick={handleClick}>
          <Icon alt="statistics" src={StatisticsIcon} />
          Statystyki
        </LeftPanelElement>
      </LeftSide>
      <Wrapper>
        {currentTab === 1 ? (
          <>
            <Scheduler schedulerEvents={schedulerEvents}/>
            <Rightbar />
          </>
        ) : currentTab === 2 ? (
          <SchedulerHistory schedulerHistoryEvents={schedulerHistoryEvents}/>
        ) : currentTab === 3 ? (
          <StatsDiv><Statistics /></StatsDiv> 
        ) : (
          <LogoWrapper>
            <Logo alt="logo" src="https://plannaplan.pl/img/logo.svg" />
            <Text> plan na plan </Text>
          </LogoWrapper>
        )}
      </Wrapper>
    </Wrap>
  );
};