Proof of concept
This commit is contained in:
parent
ebebdd9def
commit
6992906450
21
src/App.tsx
21
src/App.tsx
@ -75,8 +75,25 @@ function App() {
|
||||
<Schedule data={appointments} />
|
||||
</div>
|
||||
<div className="wraper__rightbar">
|
||||
<RightBar 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)}}/>
|
||||
<RightBar
|
||||
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>
|
||||
|
||||
|
63
src/buisnesslogic/BuisnessLogicProvider.tsx
Normal file
63
src/buisnesslogic/BuisnessLogicProvider.tsx
Normal 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;
|
5
src/buisnesslogic/BusinessLogicContext.ts
Normal file
5
src/buisnesslogic/BusinessLogicContext.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import React from "react";
|
||||
|
||||
const BusinessLogicContext = React.createContext({});
|
||||
|
||||
export default BusinessLogicContext;
|
5
src/buisnesslogic/models/user.ts
Normal file
5
src/buisnesslogic/models/user.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export type User = {
|
||||
name?: string;
|
||||
surname?: string;
|
||||
ticket: string;
|
||||
};
|
@ -1,6 +1,8 @@
|
||||
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;
|
||||
@ -17,10 +19,16 @@ export default class RightBar extends React.Component<
|
||||
render() {
|
||||
return (
|
||||
<div className="right-bar">
|
||||
<div className="right-bar__text">
|
||||
Hubert Wrzesiński<br></br>
|
||||
Semestr zimowy 2020/2021
|
||||
</div>
|
||||
<BusinessLogicContext.Consumer>
|
||||
{(context) => (
|
||||
<h1>
|
||||
{JSON.stringify(
|
||||
(context as BuisnessProvided).states.user
|
||||
?.ticket
|
||||
)}
|
||||
</h1>
|
||||
)}
|
||||
</BusinessLogicContext.Consumer>
|
||||
{this.props.lectures.map((classgroup, index) => (
|
||||
<Class
|
||||
onClassHover={this.props.onClassHover}
|
||||
|
@ -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
|
||||
|
||||
handleClose: () => void;
|
||||
}
|
||||
|
||||
export const Profile : FC<ProfileProps> = ({anchorEl, handleClose, ...restProps}) => {
|
||||
|
||||
export const Profile: FC<ProfileProps> = ({
|
||||
anchorEl,
|
||||
handleClose,
|
||||
...restProps
|
||||
}) => {
|
||||
return (
|
||||
<Menu
|
||||
className="top-bar__menu"
|
||||
@ -21,7 +24,17 @@ export const Profile : FC<ProfileProps> = ({anchorEl, handleClose, ...restProps}
|
||||
>
|
||||
<MenuItem>Profile</MenuItem>
|
||||
<MenuItem>My account</MenuItem>
|
||||
<MenuItem>Logout</MenuItem>
|
||||
<BusinessLogicContext.Consumer>
|
||||
{(context) => (
|
||||
<MenuItem
|
||||
onClick={() => {
|
||||
(context as BuisnessProvided).reducers();
|
||||
}}
|
||||
>
|
||||
Logout
|
||||
</MenuItem>
|
||||
)}
|
||||
</BusinessLogicContext.Consumer>
|
||||
</Menu>
|
||||
);
|
||||
};
|
||||
|
@ -1,10 +1,13 @@
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import App from "./App";
|
||||
import BuisnessLogicProvider from "./buisnesslogic/BuisnessLogicProvider";
|
||||
|
||||
ReactDOM.render(
|
||||
<React.Fragment>
|
||||
<BuisnessLogicProvider>
|
||||
<App />
|
||||
</BuisnessLogicProvider>
|
||||
</React.Fragment>,
|
||||
document.getElementById("root")
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user