diff --git a/src/App.tsx b/src/App.tsx index 4e946f1..5897bee 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,6 +5,8 @@ import "./App.scss"; import Schedule from "./components/Calendar/"; import { appointments } from "./components/Calendar/appointments"; import RightBar from "./components/RightBar"; +import { lectures } from "./lectures"; + import BusinessLogicContext from "./businesslogic/BusinessLogicContext"; import { BuisnessProvided } from "./businesslogic/BusinessLogicProvider"; @@ -12,47 +14,6 @@ function App() { 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", - }, - ], - }, - ]; - return (
@@ -85,23 +46,11 @@ function App() {
{ - 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 - ); + lectures={lectures} + onGroupMouseOver={(id, name) => { + console.log("XD"); }} + onGroupClick={(id, name) => {}} />
diff --git a/src/components/Class/index.tsx b/src/components/Class/index.tsx deleted file mode 100644 index 4cd8bd6..0000000 --- a/src/components/Class/index.tsx +++ /dev/null @@ -1,78 +0,0 @@ -import React from "react"; -import "./index.scss"; -import Collapse from "@material-ui/core/Collapse"; -import ExpandIcon from "./expand.png"; - -type ClassType = { - group_id: string; - day: string; - time: string; - lecturer: string; - room: string; -}; - -export type Group = { - classname: string; - classgroups: Array; -}; - -interface ClassProps { - onClassHover: (group_id: String, class_id: String) => void; - onClassClick: (group_id: String, class_id: String) => void; - data: Group; -} - -interface ClassState { - open: boolean; -} - -export default class Class extends React.Component { - constructor(props: ClassProps) { - super(props); - - this.Open = this.Open.bind(this); - this.state = { - open: false, - }; - } - - Open(e: React.MouseEvent) { - this.setState({ - open: !this.state.open, - }); - } - - render() { - return ( -
-
{this.props.data.classname}
- - {this.props.data.classgroups.map((classgroup, index) => ( -
-

- this.props.onClassHover( - this.props.data.classname, - this.props.data.classgroups[index].group_id - ) - } - onClick={() => - this.props.onClassClick( - this.props.data.classname, - this.props.data.classgroups[index].group_id - ) - } - > - {classgroup.group_id} {classgroup.day} {classgroup.time}{" "} - {classgroup.room}

{classgroup.lecturer} -

{" "} -
- ))} -
-
- expand -
-
- ); - } -} diff --git a/src/components/Class/expand.png b/src/components/RightBar/LectureCard/expand.png similarity index 100% rename from src/components/Class/expand.png rename to src/components/RightBar/LectureCard/expand.png diff --git a/src/components/Class/index.scss b/src/components/RightBar/LectureCard/index.scss similarity index 100% rename from src/components/Class/index.scss rename to src/components/RightBar/LectureCard/index.scss diff --git a/src/components/RightBar/LectureCard/index.tsx b/src/components/RightBar/LectureCard/index.tsx new file mode 100644 index 0000000..382c3a1 --- /dev/null +++ b/src/components/RightBar/LectureCard/index.tsx @@ -0,0 +1,39 @@ +import React from "react"; +import "./index.scss"; +import Collapse from "@material-ui/core/Collapse"; +import ExpandIcon from "./expand.png"; +import { Lecture } from "../../../lectures"; + +interface LectureCardProps { + onGroupMouseOver: (id: string, name: string) => void; + onGroupClick: (id: string, name: string) => void; + onCardClick: (e: React.MouseEvent) => void; + lecture: Lecture; + id: string; + isSelected: boolean; +} + +export default function LectureCard({ onGroupMouseOver, onGroupClick, onCardClick, lecture, id, isSelected }: LectureCardProps) { + return ( +
+
{lecture.name}
+ + {lecture.groups.map((group, index) => ( +
onGroupMouseOver(group.id, lecture.name)} + onClick={() => onGroupClick(group.id, lecture.name)} + > +

+ {group.id} {group.day} {group.time} {group.room}

{group.lecturer} +

{" "} +
+ ))} +
+
+ expand +
+
+ ); +} diff --git a/src/components/RightBar/index.tsx b/src/components/RightBar/index.tsx index b2d70aa..4cec1df 100644 --- a/src/components/RightBar/index.tsx +++ b/src/components/RightBar/index.tsx @@ -1,44 +1,44 @@ -import React from "react"; +import React, { useState } from "react"; import "./index.scss"; -import Class, { Group } from "../Class"; +import { Lecture } from "../../lectures"; +import LectureCard from "./LectureCard"; import BusinessLogicContext from "../../businesslogic/BusinessLogicContext"; import { BuisnessProvided } from "../../businesslogic/BusinessLogicProvider"; interface RightBarProps { - onClassHover: (group_id: String, class_id: String) => void; - onClassClick: (group_id: String, class_id: String) => void; - lectures: Array; + onGroupMouseOver: (id: string, name: string) => void; + onGroupClick: (id: string, name: string) => void; + lectures: Array; } -interface RightBarState {} +export default function RightBar({ lectures, onGroupMouseOver, onGroupClick }: RightBarProps) { + const [selectedCardId, setSelectedCardId] = useState(null); -export default class RightBar extends React.Component< - RightBarProps, - RightBarState -> { - render() { - return ( -
- - {(context) => ( -

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

- )} -
-

Semestr zimowy 2020/2021

- {this.props.lectures.map((classgroup, index) => ( - - ))} + const onCardClick = (e: React.MouseEvent) => { + const target = e.currentTarget as HTMLElement; + selectedCardId === target.id ? setSelectedCardId(null) : setSelectedCardId(target.id); + }; + + return ( +
+ + {(context) =>

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

} +
+
+ Hubert Wrzesiński

+ Semestr zimowy 2020/2021
- ); - } + {lectures.map((lecture, index) => ( + + ))} +
+ ); } diff --git a/src/index.tsx b/src/index.tsx index d09a869..628c5bc 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -4,10 +4,10 @@ import App from "./App"; import BuisnessLogicProvider from "./businesslogic/BusinessLogicProvider"; ReactDOM.render( - + <> - , + , document.getElementById("root") ); diff --git a/src/lectures.ts b/src/lectures.ts new file mode 100644 index 0000000..fbc7068 --- /dev/null +++ b/src/lectures.ts @@ -0,0 +1,53 @@ +export interface Lecture { + name: string; + groups: Array; +} + +interface Group { + id: string; + day: string; + time: string; + lecturer: string; + room: string; +} + +export const lectures: Array = [ + { + name: "E-gospodarka - narzędzia i bezpieczeństwo", + groups: [ + { + id: "1CB", + day: "Pn", + time: "10:00", + lecturer: "dr inż. Michał Ren", + room: "A2-01", + }, + { + id: "1XD", + day: "Wt", + time: "12:00", + lecturer: "dr inż. Michał Ren", + room: "A3-01", + }, + ], + }, + { + name: "Statystyka", + groups: [ + { + id: "2CB", + day: "Pn", + time: "10:00", + lecturer: "dr inż. Michał Ren", + room: "A2-01", + }, + { + id: "2XD", + day: "Wt", + time: "12:00", + lecturer: "dr inż. Michał Ren", + room: "A3-01", + }, + ], + }, +]; diff --git a/tsconfig.json b/tsconfig.json index f2850b7..97ba7e5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,25 +1,19 @@ { - "compilerOptions": { - "target": "es5", - "lib": [ - "dom", - "dom.iterable", - "esnext" - ], - "allowJs": true, - "skipLibCheck": true, - "esModuleInterop": true, - "allowSyntheticDefaultImports": true, - "strict": true, - "forceConsistentCasingInFileNames": true, - "module": "esnext", - "moduleResolution": "node", - "resolveJsonModule": true, - "isolatedModules": true, - "noEmit": true, - "jsx": "react" - }, - "include": [ - "src" - ] + "compilerOptions": { + "target": "es5", + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react" + }, + "include": ["src"] }