Proof of concept

This commit is contained in:
Filip Izydorczyk 2020-06-17 15:19:51 +02:00
parent ebebdd9def
commit 6992906450
7 changed files with 219 additions and 105 deletions

View File

@ -75,8 +75,25 @@ function App() {
<Schedule data={appointments} /> <Schedule data={appointments} />
</div> </div>
<div className="wraper__rightbar"> <div className="wraper__rightbar">
<RightBar onClassHover={(group_id,class_id)=>{console.log("group id: ",group_id,"class id",class_id)}} lectures={data} <RightBar
onClassClick={(group_id,class_id)=>{console.log("group id: ",group_id,"class id",class_id)}}/> onClassHover={(group_id, class_id) => {
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
);
}}
/>
</div> </div>
</div> </div>

View File

@ -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<Props, BuisnessState> {
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 (
<BusinessLogicContext.Provider
value={{
states: this.state,
reducers: () => {
this.logout();
},
}}
>
{this.props.children}
</BusinessLogicContext.Provider>
);
}
}
export default BusinessLogicProvider;

View File

@ -0,0 +1,5 @@
import React from "react";
const BusinessLogicContext = React.createContext({});
export default BusinessLogicContext;

View File

@ -0,0 +1,5 @@
export type User = {
name?: string;
surname?: string;
ticket: string;
};

View File

@ -1,6 +1,8 @@
import React from "react"; import React from "react";
import "./index.scss"; import "./index.scss";
import Class, { Group } from "../Class"; import Class, { Group } from "../Class";
import BusinessLogicContext from "../../buisnesslogic/BusinessLogicContext";
import { BuisnessProvided } from "../../buisnesslogic/BuisnessLogicProvider";
interface RightBarProps { interface RightBarProps {
onClassHover: (group_id: String, class_id: String) => void; onClassHover: (group_id: String, class_id: String) => void;
@ -17,10 +19,16 @@ export default class RightBar extends React.Component<
render() { render() {
return ( return (
<div className="right-bar"> <div className="right-bar">
<div className="right-bar__text"> <BusinessLogicContext.Consumer>
Hubert Wrzesiński<br></br> {(context) => (
Semestr zimowy 2020/2021 <h1>
</div> {JSON.stringify(
(context as BuisnessProvided).states.user
?.ticket
)}
</h1>
)}
</BusinessLogicContext.Consumer>
{this.props.lectures.map((classgroup, index) => ( {this.props.lectures.map((classgroup, index) => (
<Class <Class
onClassHover={this.props.onClassHover} onClassHover={this.props.onClassHover}

View File

@ -1,15 +1,18 @@
import { Menu, MenuItem } from "@material-ui/core"; import { Menu, MenuItem } from "@material-ui/core";
import React, { FC } from "react"; import React, { FC } from "react";
import BusinessLogicContext from "../../buisnesslogic/BusinessLogicContext";
import { BuisnessProvided } from "../../buisnesslogic/BuisnessLogicProvider";
interface ProfileProps { interface ProfileProps {
anchorEl: HTMLElement | null; anchorEl: HTMLElement | null;
handleClose: () => void handleClose: () => void;
} }
export const Profile : FC<ProfileProps> = ({anchorEl, handleClose, ...restProps}) => { export const Profile: FC<ProfileProps> = ({
anchorEl,
handleClose,
...restProps
}) => {
return ( return (
<Menu <Menu
className="top-bar__menu" className="top-bar__menu"
@ -21,7 +24,17 @@ export const Profile : FC<ProfileProps> = ({anchorEl, handleClose, ...restProps}
> >
<MenuItem>Profile</MenuItem> <MenuItem>Profile</MenuItem>
<MenuItem>My account</MenuItem> <MenuItem>My account</MenuItem>
<MenuItem>Logout</MenuItem> <BusinessLogicContext.Consumer>
{(context) => (
<MenuItem
onClick={() => {
(context as BuisnessProvided).reducers();
}}
>
Logout
</MenuItem>
)}
</BusinessLogicContext.Consumer>
</Menu> </Menu>
); );
}; };

View File

@ -1,10 +1,13 @@
import React from "react"; import React from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import App from "./App"; import App from "./App";
import BuisnessLogicProvider from "./buisnesslogic/BuisnessLogicProvider";
ReactDOM.render( ReactDOM.render(
<React.Fragment> <React.Fragment>
<BuisnessLogicProvider>
<App /> <App />
</BuisnessLogicProvider>
</React.Fragment>, </React.Fragment>,
document.getElementById("root") document.getElementById("root")
); );