Skip to content

Commit

Permalink
lectureGroupBlock .jsx nd shape.jsx into tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
useruseruse committed Sep 9, 2023
1 parent 3dc36fa commit 83deb14
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';

import { useTranslation } from 'react-i18next';
import { appBoundClassNames as classNames } from '../../common/boundClassNames';

import lectureShape from '../../shapes/model/subject/LectureShape';
import lectureType from '../../shapes/model/subject/LectureType';

interface LectureGroupBlockProps {
lectureGroup: lectureType[];
isRaised: boolean;
isDimmed: boolean;
isTaken: boolean;
children?: React.ReactNode;
}

const LectureGroupBlock: React.FC<LectureGroupBlockProps> = ({
lectureGroup,
isRaised,
isDimmed,
isTaken,
children,
}) => {
const { t } = useTranslation();

const LectureGroupBlock = ({ t, lectureGroup, isRaised, isDimmed, isTaken, children }) => {
return (
<div
className={classNames(
Expand All @@ -25,11 +39,4 @@ const LectureGroupBlock = ({ t, lectureGroup, isRaised, isDimmed, isTaken, child
);
};

LectureGroupBlock.propTypes = {
lectureGroup: PropTypes.arrayOf(lectureShape).isRequired,
isRaised: PropTypes.bool.isRequired,
isDimmed: PropTypes.bool.isRequired,
isTaken: PropTypes.bool.isRequired,
};

export default withTranslation()(React.memo(LectureGroupBlock));
export default React.memo(LectureGroupBlock);
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';
import { useTranslation } from 'react-i18next';

import { appBoundClassNames as classNames } from '../../common/boundClassNames';
import { getProfessorsShortStr, getClassroomStr } from '../../utils/lectureUtils';

import lectureShape from '../../shapes/model/subject/LectureShape';
import lectureType from '@/shapes/model/subject/LectureType';

const LectureGroupBlockRow = ({
t,
interface LectureGroupBlockRowProps {
lecture: lectureType;
isHighlighted: boolean;
inTimetable: boolean;
isTimetableReadonly: boolean;
inCart: boolean;
fromCart: boolean;
addToCart: (lecture: lectureType) => void;
addToTable: (lecture: lectureType) => void;
deleteFromCart: (lecture: lectureType) => void;
onMouseOver?: (lecture: lectureType) => void;
onMouseOut?: (lecture: lectureType) => void;
onClick?: (lecture: lectureType) => void;
}

const LectureGroupBlockRow: React.FC<LectureGroupBlockRowProps> = ({
lecture,
isHighlighted,
inTimetable,
Expand All @@ -22,6 +35,7 @@ const LectureGroupBlockRow = ({
onMouseOut,
onClick,
}) => {
const { t } = useTranslation();
const getClass = (lec) => {
switch (lec.class_title.length) {
case 1:
Expand All @@ -37,17 +51,17 @@ const LectureGroupBlockRow = ({
? (event) => {
onMouseOver(lecture);
}
: null;
: undefined;
const handleMouseOut = onMouseOut
? (event) => {
onMouseOut(lecture);
}
: null;
: undefined;
const handleClick = onClick
? (event) => {
onClick(lecture);
}
: null;
: undefined;
const handleDeleteFromCartClick = (event) => {
event.stopPropagation();
deleteFromCart(lecture);
Expand Down Expand Up @@ -133,19 +147,4 @@ const LectureGroupBlockRow = ({
);
};

LectureGroupBlockRow.propTypes = {
lecture: lectureShape.isRequired,
isHighlighted: PropTypes.bool.isRequired,
inTimetable: PropTypes.bool.isRequired,
isTimetableReadonly: PropTypes.bool.isRequired,
inCart: PropTypes.bool.isRequired,
fromCart: PropTypes.bool.isRequired,
addToCart: PropTypes.func.isRequired,
addToTable: PropTypes.func.isRequired,
deleteFromCart: PropTypes.func.isRequired,
onMouseOver: PropTypes.func,
onMouseOut: PropTypes.func,
onClick: PropTypes.func,
};

export default withTranslation()(React.memo(LectureGroupBlockRow));
export default React.memo(LectureGroupBlockRow);
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';
import { useTranslation } from 'react-i18next';

import { appBoundClassNames as classNames } from '../../common/boundClassNames';
import { getProfessorsShortStr } from '../../utils/lectureUtils';
import lectureType from '../../shapes/model/subject/LectureType';

import lectureShape from '../../shapes/model/subject/LectureShape';
interface LectureGroupSimpleBlockProps {
lectures: lectureType[];
}

const LectureGroupSimpleBlock = ({ t, lectures }) => {
const LectureGroupSimpleBlock: React.FC<LectureGroupSimpleBlockProps> = ({ lectures }) => {
const { t } = useTranslation();
const getClass = (lecture) => {
if (!lecture.class_title) {
return classNames('');
Expand Down Expand Up @@ -37,8 +41,4 @@ const LectureGroupSimpleBlock = ({ t, lectures }) => {
);
};

LectureGroupSimpleBlock.propTypes = {
lectures: PropTypes.arrayOf(lectureShape).isRequired,
};

export default withTranslation()(React.memo(LectureGroupSimpleBlock));
export default React.memo(LectureGroupSimpleBlock);
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';
import { useTranslation } from 'react-i18next';

import { appBoundClassNames as classNames } from '../../common/boundClassNames';

import lectureShape from '../../shapes/model/subject/LectureShape';
import lectureType from '@/shapes/model/subject/LectureType';

interface LectureSimpleBlockProps {
lecture: lectureType;
isRaised: boolean;
isDimmed: boolean;
hasReview: boolean;
onClick?: (lecture: lectureType) => void; ///
}
const LectureSimpleBlock: React.FC<LectureSimpleBlockProps> = ({
lecture,
isRaised,
isDimmed,
hasReview,
onClick,
}) => {
const { t } = useTranslation();

const LectureSimpleBlock = ({ t, lecture, isRaised, isDimmed, hasReview, onClick }) => {
const handleClick = onClick
? (event) => {
onClick(lecture);
}
: null;
: undefined;

return (
<div
Expand All @@ -33,12 +48,12 @@ const LectureSimpleBlock = ({ t, lecture, isRaised, isDimmed, hasReview, onClick
);
};

LectureSimpleBlock.propTypes = {
lecture: lectureShape.isRequired,
isRaised: PropTypes.bool.isRequired,
isDimmed: PropTypes.bool.isRequired,
hasReview: PropTypes.bool.isRequired,
onClick: PropTypes.func.isRequired,
};
// LectureSimpleBlock.propTypes = {
// lecture: lectureShape.isRequired,
// isRaised: PropTypes.bool.isRequired,
// isDimmed: PropTypes.bool.isRequired,
// hasReview: PropTypes.bool.isRequired,
// onClick: PropTypes.func.isRequired,
// };

export default withTranslation()(React.memo(LectureSimpleBlock));
export default React.memo(LectureSimpleBlock);
13 changes: 13 additions & 0 deletions src/shapes/model/subject/ClasstimeShape.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
interface classtimeType {
building_code: string;
classroom: string;
classroom_en: string;
classroom_short: string;
classroom_short_en: string;
room_name: string;
day: number;
begin: number;
end: number;
}

export default classtimeType;
8 changes: 8 additions & 0 deletions src/shapes/model/subject/ExamtimeShape.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type examtimeType = {
day: number;
str: string;
str_en: string;
begin: number;
end: number;
};
export default examtimeType;
40 changes: 40 additions & 0 deletions src/shapes/model/subject/LectureType.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import classtimeType from './ClasstimeShape';
import examtimeType from './ExamtimeShape';
import nestedProfessorType from './NestedProfessorShape';

interface lectureType {
id: number;
title: string;
title_en: string;
course: number;
old_code: string;
class_no: string;
year: number;
semester: 1 | 2 | 3 | 4;
code: string;
department: number;
department_code: string;
department_name: string;
department_name_en: string;
type: string;
type_en: string;
limit: number;
num_people: number;
is_english: boolean;
num_classes: number;
num_labs: number;
credit: number;
credit_au: number;
common_title: string;
common_title_en: string;
class_title: string;
class_title_en: string;
review_total_weight: number;
professors: nestedProfessorType;
grade: number;
load: number;
speech: number;
classtimes: classtimeType[];
examtimes: examtimeType[];
}
export default lectureType;
7 changes: 7 additions & 0 deletions src/shapes/model/subject/NestedProfessorShape.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type nestedProfessorType = {
name: string;
name_en: string;
professor_id: number;
review_total_weight: number;
};
export default nestedProfessorType;

0 comments on commit 83deb14

Please sign in to comment.