diff --git a/src/App.tsx b/src/App.tsx index 9e8ec54..70c2e30 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,82 +7,99 @@ import { appointments } from "./components/Calendar/appointments"; import RightBar from "./components/RightBar"; function App() { - const [isOpenTransfer, setOpenTransfer] = useState(false); - const [text, setText] = useState(""); + const [isOpenTransfer, setOpenTransfer] = useState(false); + const [text, setText] = useState(""); - var data = [ - { - classname: "E-gospodarka - narzędzia i bezpieczeństwo", - classgroups: [ - { - group_id: "1CB", - day: "Pn", - time: "10:00", - lecturer: "dr inż. Michał Ren", - room: "A2-01", - }, - { - group_id: "1XD", - day: "Wt", - time: "12:00", - lecturer: "dr inż. Michał Ren", - room: "A3-01", - }, - ], - }, - { - classname: "Statystyka", - classgroups: [ - { - group_id: "2CB", - day: "Pn", - time: "10:00", - lecturer: "dr inż. Michał Ren", - room: "A2-01", - }, - { - group_id: "2XD", - day: "Wt", - time: "12:00", - lecturer: "dr inż. Michał Ren", - room: "A3-01", - }, - ], - }, - ]; + var data = [ + { + classname: "E-gospodarka - narzędzia i bezpieczeństwo", + classgroups: [ + { + group_id: "1CB", + day: "Pn", + time: "10:00", + lecturer: "dr inż. Michał Ren", + room: "A2-01", + }, + { + group_id: "1XD", + day: "Wt", + time: "12:00", + lecturer: "dr inż. Michał Ren", + room: "A3-01", + }, + ], + }, + { + classname: "Statystyka", + classgroups: [ + { + group_id: "2CB", + day: "Pn", + time: "10:00", + lecturer: "dr inż. Michał Ren", + room: "A2-01", + }, + { + group_id: "2XD", + day: "Wt", + time: "12:00", + lecturer: "dr inż. Michał Ren", + room: "A3-01", + }, + ], + }, + ]; - return ( -
- { - setText(e.target.value); - }} - handleTransfer={(e) => { - setOpenTransfer(!isOpenTransfer); - }} - onLangChange={(e) => { - console.log(e); - }} - /> - { - setOpenTransfer(!isOpenTransfer); - }} - /> -
-
- -
-
- {console.log("group id: ",group_id,"class id",class_id)}} lectures={data} - onClassClick={(group_id,class_id)=>{console.log("group id: ",group_id,"class id",class_id)}}/> -
-
+ return ( +
+ { + setText(e.target.value); + }} + handleTransfer={(e) => { + setOpenTransfer(!isOpenTransfer); + }} + onLangChange={(e) => { + console.log(e); + }} + /> + { + setOpenTransfer(!isOpenTransfer); + }} + /> +
+
+ +
+
+ { + console.log( + "group id: ", + group_id, + "class id", + class_id + ); + }} + lectures={data} + onClassClick={(group_id, class_id) => { + console.log( + "group id: ", + group_id, + "class id", + class_id + ); + }} + /> +
+
-

{text}

-
- ); +

{text}

+
+ ); } -export default App; \ No newline at end of file +export default App; diff --git a/src/buisnesslogic/BuisnessLogicProvider.tsx b/src/buisnesslogic/BuisnessLogicProvider.tsx new file mode 100644 index 0000000..410b2ed --- /dev/null +++ b/src/buisnesslogic/BuisnessLogicProvider.tsx @@ -0,0 +1,63 @@ +import BusinessLogicContext from "./BusinessLogicContext"; +import React, { Component } from "react"; +import { User } from "./models/user"; + +export interface BuisnessProvided { + states: BuisnessState; + reducers: () => void; +} + +interface BuisnessState { + user: User | null; +} + +interface Props {} + +class BusinessLogicProvider extends Component { + constructor(props: Props) { + super(props); + this.state = { + user: null, + }; + } + + componentDidMount() { + this.login(); + } + + login() { + const urlParams = new URLSearchParams(window.location.search); + const ticket = urlParams.get("ticket"); + + if (!ticket && !this.state.user) { + window.location.replace( + `https://cas.amu.edu.pl/cas/login?service=${window.origin}&locale=pl` + ); + } else if (ticket && !this.state.user) { + this.setState({ user: { ticket } }); + } + } + + logout() { + window.location.replace( + `https://cas.amu.edu.pl/cas/logout?service=${window.origin}` + ); + } + + render() { + return ( + { + this.logout(); + }, + }} + > + {this.props.children} + + ); + } +} + +export default BusinessLogicProvider; diff --git a/src/buisnesslogic/BusinessLogicContext.ts b/src/buisnesslogic/BusinessLogicContext.ts new file mode 100644 index 0000000..40ffea1 --- /dev/null +++ b/src/buisnesslogic/BusinessLogicContext.ts @@ -0,0 +1,5 @@ +import React from "react"; + +const BusinessLogicContext = React.createContext({}); + +export default BusinessLogicContext; diff --git a/src/buisnesslogic/models/user.ts b/src/buisnesslogic/models/user.ts new file mode 100644 index 0000000..447d9e5 --- /dev/null +++ b/src/buisnesslogic/models/user.ts @@ -0,0 +1,5 @@ +export type User = { + name?: string; + surname?: string; + ticket: string; +}; diff --git a/src/components/RightBar/index.tsx b/src/components/RightBar/index.tsx index 3d1377a..0c3b5f7 100644 --- a/src/components/RightBar/index.tsx +++ b/src/components/RightBar/index.tsx @@ -1,35 +1,43 @@ import React from "react"; import "./index.scss"; import Class, { Group } from "../Class"; +import BusinessLogicContext from "../../buisnesslogic/BusinessLogicContext"; +import { BuisnessProvided } from "../../buisnesslogic/BuisnessLogicProvider"; interface RightBarProps { - onClassHover: (group_id: String, class_id: String) => void; - onClassClick: (group_id: String, class_id: String) => void; - lectures: Array; + onClassHover: (group_id: String, class_id: String) => void; + onClassClick: (group_id: String, class_id: String) => void; + lectures: Array; } interface RightBarState {} export default class RightBar extends React.Component< - RightBarProps, - RightBarState + RightBarProps, + RightBarState > { - render() { - return ( -
-
- Hubert Wrzesiński

- Semestr zimowy 2020/2021 -
- {this.props.lectures.map((classgroup, index) => ( - - ))} -
- ); - } + render() { + return ( +
+ + {(context) => ( +

+ {JSON.stringify( + (context as BuisnessProvided).states.user + ?.ticket + )} +

+ )} +
+ {this.props.lectures.map((classgroup, index) => ( + + ))} +
+ ); + } } diff --git a/src/components/TopBar/Profile.tsx b/src/components/TopBar/Profile.tsx index 8b0a920..a97ec9a 100644 --- a/src/components/TopBar/Profile.tsx +++ b/src/components/TopBar/Profile.tsx @@ -1,15 +1,18 @@ import { Menu, MenuItem } from "@material-ui/core"; import React, { FC } from "react"; - +import BusinessLogicContext from "../../buisnesslogic/BusinessLogicContext"; +import { BuisnessProvided } from "../../buisnesslogic/BuisnessLogicProvider"; interface ProfileProps { - anchorEl: HTMLElement | null; - handleClose: () => void - + anchorEl: HTMLElement | null; + handleClose: () => void; } -export const Profile : FC = ({anchorEl, handleClose, ...restProps}) => { - +export const Profile: FC = ({ + anchorEl, + handleClose, + ...restProps +}) => { return ( = ({anchorEl, handleClose, ...restProps} > Profile My account - Logout + + {(context) => ( + { + (context as BuisnessProvided).reducers(); + }} + > + Logout + + )} + ); }; diff --git a/src/index.tsx b/src/index.tsx index 5200822..9b0365f 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,10 +1,13 @@ import React from "react"; import ReactDOM from "react-dom"; import App from "./App"; +import BuisnessLogicProvider from "./buisnesslogic/BuisnessLogicProvider"; ReactDOM.render( - + + + , document.getElementById("root") );