Refactored
This commit is contained in:
parent
9da1dfd51f
commit
124170492c
31
src/App.tsx
31
src/App.tsx
@ -5,6 +5,8 @@ import "./App.scss";
|
|||||||
import Schedule from "./components/Calendar/";
|
import Schedule from "./components/Calendar/";
|
||||||
import { appointments } from "./components/Calendar/appointments";
|
import { appointments } from "./components/Calendar/appointments";
|
||||||
import RightBar from "./components/RightBar";
|
import RightBar from "./components/RightBar";
|
||||||
|
import BusinessLogicContext from "./businesslogic/BusinessLogicContext";
|
||||||
|
import { BuisnessProvided } from "./businesslogic/BusinessLogicProvider";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [isOpenTransfer, setOpenTransfer] = useState(false);
|
const [isOpenTransfer, setOpenTransfer] = useState(false);
|
||||||
@ -53,17 +55,24 @@ function App() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<TopBar
|
<BusinessLogicContext.Consumer>
|
||||||
textChangeHandler={(e) => {
|
{(context) => (
|
||||||
setText(e.target.value);
|
<TopBar
|
||||||
}}
|
textChangeHandler={(e) => {
|
||||||
handleTransfer={(e) => {
|
setText(e.target.value);
|
||||||
setOpenTransfer(!isOpenTransfer);
|
}}
|
||||||
}}
|
handleTransfer={(e) => {
|
||||||
onLangChange={(e) => {
|
setOpenTransfer(!isOpenTransfer);
|
||||||
console.log(e);
|
}}
|
||||||
}}
|
onLangChange={(e) => {
|
||||||
/>
|
console.log(e);
|
||||||
|
}}
|
||||||
|
handleLogout={() => {
|
||||||
|
(context as BuisnessProvided).reducers.userlogout();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</BusinessLogicContext.Consumer>
|
||||||
<Transfer
|
<Transfer
|
||||||
isOpen={isOpenTransfer}
|
isOpen={isOpenTransfer}
|
||||||
handleClose={(e) => {
|
handleClose={(e) => {
|
||||||
|
@ -4,7 +4,9 @@ import { User } from "./models/user";
|
|||||||
|
|
||||||
export interface BuisnessProvided {
|
export interface BuisnessProvided {
|
||||||
states: BusinessState;
|
states: BusinessState;
|
||||||
reducers: () => void;
|
reducers: {
|
||||||
|
userlogout: () => void;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BusinessState {
|
interface BusinessState {
|
||||||
@ -42,11 +44,15 @@ class BusinessLogicProvider extends Component<Props, BusinessState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
redirectToCASLogoutService() {
|
redirectToCASLogoutService() {
|
||||||
window.location.replace(`https://cas.amu.edu.pl/cas/logout?service=${window.origin}`);
|
window.location.replace(
|
||||||
|
`https://cas.amu.edu.pl/cas/logout?service=${window.origin}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
redirectToCASLoginService() {
|
redirectToCASLoginService() {
|
||||||
window.location.replace(`https://cas.amu.edu.pl/cas/login?service=${window.origin}&locale=pl`);
|
window.location.replace(
|
||||||
|
`https://cas.amu.edu.pl/cas/login?service=${window.origin}&locale=pl`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@ -54,8 +60,10 @@ class BusinessLogicProvider extends Component<Props, BusinessState> {
|
|||||||
<BusinessLogicContext.Provider
|
<BusinessLogicContext.Provider
|
||||||
value={{
|
value={{
|
||||||
states: this.state,
|
states: this.state,
|
||||||
reducers: () => {
|
reducers: {
|
||||||
this.logout();
|
userlogout: () => {
|
||||||
|
this.logout();
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -21,14 +21,15 @@ export default class RightBar extends React.Component<
|
|||||||
<div className="right-bar">
|
<div className="right-bar">
|
||||||
<BusinessLogicContext.Consumer>
|
<BusinessLogicContext.Consumer>
|
||||||
{(context) => (
|
{(context) => (
|
||||||
<h1>
|
<p>
|
||||||
{JSON.stringify(
|
{JSON.stringify(
|
||||||
(context as BuisnessProvided).states.user
|
(context as BuisnessProvided).states.user
|
||||||
?.ticket
|
?.ticket
|
||||||
)}
|
)}
|
||||||
</h1>
|
</p>
|
||||||
)}
|
)}
|
||||||
</BusinessLogicContext.Consumer>
|
</BusinessLogicContext.Consumer>
|
||||||
|
<p>Semestr zimowy 2020/2021</p>
|
||||||
{this.props.lectures.map((classgroup, index) => (
|
{this.props.lectures.map((classgroup, index) => (
|
||||||
<Class
|
<Class
|
||||||
onClassHover={this.props.onClassHover}
|
onClassHover={this.props.onClassHover}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
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 "../../businesslogic/BusinessLogicContext";
|
|
||||||
import { BuisnessProvided } from "../../businesslogic/BusinessLogicProvider";
|
|
||||||
|
|
||||||
interface ProfileProps {
|
interface ProfileProps {
|
||||||
anchorEl: HTMLElement | null;
|
anchorEl: HTMLElement | null;
|
||||||
handleClose: () => void;
|
handleClose: () => void;
|
||||||
|
handleLogout: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Profile: FC<ProfileProps> = ({
|
export const Profile: FC<ProfileProps> = ({
|
||||||
anchorEl,
|
anchorEl,
|
||||||
handleClose,
|
handleClose,
|
||||||
|
handleLogout,
|
||||||
...restProps
|
...restProps
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
@ -24,17 +24,13 @@ export const Profile: FC<ProfileProps> = ({
|
|||||||
>
|
>
|
||||||
<MenuItem>Profile</MenuItem>
|
<MenuItem>Profile</MenuItem>
|
||||||
<MenuItem>My account</MenuItem>
|
<MenuItem>My account</MenuItem>
|
||||||
<BusinessLogicContext.Consumer>
|
<MenuItem
|
||||||
{(context) => (
|
onClick={() => {
|
||||||
<MenuItem
|
handleLogout();
|
||||||
onClick={() => {
|
}}
|
||||||
(context as BuisnessProvided).reducers();
|
>
|
||||||
}}
|
Logout
|
||||||
>
|
</MenuItem>
|
||||||
Logout
|
|
||||||
</MenuItem>
|
|
||||||
)}
|
|
||||||
</BusinessLogicContext.Consumer>
|
|
||||||
</Menu>
|
</Menu>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -12,7 +12,10 @@ import { Profile } from "./Profile";
|
|||||||
interface TopBarProps {
|
interface TopBarProps {
|
||||||
handleTransfer: (e: React.MouseEvent) => void;
|
handleTransfer: (e: React.MouseEvent) => void;
|
||||||
onLangChange: (lang: boolean) => void;
|
onLangChange: (lang: boolean) => void;
|
||||||
textChangeHandler: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
handleLogout: () => void;
|
||||||
|
textChangeHandler: (
|
||||||
|
e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
|
||||||
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TopBarState {
|
interface TopBarState {
|
||||||
@ -64,29 +67,55 @@ export default class TopBar extends React.Component<TopBarProps, TopBarState> {
|
|||||||
return (
|
return (
|
||||||
<div className="top-bar">
|
<div className="top-bar">
|
||||||
<div className="top-bar__logo">
|
<div className="top-bar__logo">
|
||||||
<img className="top-bar__logo-image" alt="logo" src="https://plannaplan.pl/img/logo.svg" />
|
<img
|
||||||
|
className="top-bar__logo-image"
|
||||||
|
alt="logo"
|
||||||
|
src="https://plannaplan.pl/img/logo.svg"
|
||||||
|
/>
|
||||||
<div className="top-bar__tekst"> plan na plan </div>
|
<div className="top-bar__tekst"> plan na plan </div>
|
||||||
</div>
|
</div>
|
||||||
<div className="top-bar__input-div">
|
<div className="top-bar__input-div">
|
||||||
<img className="top-bar__input-icon" alt="search" src={Search} />
|
<img
|
||||||
|
className="top-bar__input-icon"
|
||||||
|
alt="search"
|
||||||
|
src={Search}
|
||||||
|
/>
|
||||||
<Input
|
<Input
|
||||||
placeholder="Wyszukaj..."
|
placeholder="Wyszukaj..."
|
||||||
inputProps={{ "aria-label": "description" }}
|
inputProps={{ "aria-label": "description" }}
|
||||||
className="top-bar__input-field"
|
className="top-bar__input-field"
|
||||||
onChange={(e) => this.handleChange(e)}
|
onChange={(e) => this.handleChange(e)}
|
||||||
/>
|
/>
|
||||||
<img className="top-bar__input-icon" alt="close" src={CloseIcon} />
|
<img
|
||||||
|
className="top-bar__input-icon"
|
||||||
|
alt="close"
|
||||||
|
src={CloseIcon}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="top-bar__icon-box">
|
<div className="top-bar__icon-box">
|
||||||
<img className="top-bar__icon" alt="transfer" src={Transfer} onClick={this.handleTransfer} />
|
<img
|
||||||
|
className="top-bar__icon"
|
||||||
|
alt="transfer"
|
||||||
|
src={Transfer}
|
||||||
|
onClick={this.handleTransfer}
|
||||||
|
/>
|
||||||
<img
|
<img
|
||||||
className="top-bar__icon"
|
className="top-bar__icon"
|
||||||
alt="change_language"
|
alt="change_language"
|
||||||
src={this.state.isPolish ? UK : PL}
|
src={this.state.isPolish ? UK : PL}
|
||||||
onClick={this.onLangChange}
|
onClick={this.onLangChange}
|
||||||
/>
|
/>
|
||||||
<img className="top-bar__icon" alt="profile" src={User} onClick={this.handleProfile} />
|
<img
|
||||||
<Profile anchorEl={this.state.anchorEl} handleClose={this.handleClose} />
|
className="top-bar__icon"
|
||||||
|
alt="profile"
|
||||||
|
src={User}
|
||||||
|
onClick={this.handleProfile}
|
||||||
|
/>
|
||||||
|
<Profile
|
||||||
|
anchorEl={this.state.anchorEl}
|
||||||
|
handleClose={this.handleClose}
|
||||||
|
handleLogout={this.props.handleLogout}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user