-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSemesterBlock.tsx
More file actions
109 lines (101 loc) · 3.64 KB
/
Copy pathSemesterBlock.tsx
File metadata and controls
109 lines (101 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import React, { Dispatch, SetStateAction } from "react";
import { SemesterType } from "../../types/interfaces/Semester.interface";
import { Droppable } from "@hello-pangea/dnd";
import PlannerCourseHolder from "./PlannerCourseHolder";
import DraggableItem from "../DraggableItem";
import { UserCourse } from "../../types/interfaces/Course.interface";
interface SemesterBlockProps {
semester: SemesterType;
index: number;
setPlannerCourses: Dispatch<SetStateAction<SemesterType[]>>;
setToolboxCourses: Dispatch<SetStateAction<UserCourse[]>>;
}
const seasons: string[] = ["fall", "spring", "summer", "misc"];
const SemesterBlock: React.FC<SemesterBlockProps> = ({
semester,
index,
setPlannerCourses,
setToolboxCourses,
}) => {
const seasonDropdown = (e: React.ChangeEvent<HTMLSelectElement>) => {
const newSeason = e.target.value;
setPlannerCourses((prevCourses) =>
prevCourses.map((sem) =>
sem.semesterID === semester.semesterID
? { ...sem, semesterSeason: newSeason }
: sem
)
);
};
return (
<>
<div className="flex mt-4">
<div className="flex mb-4">
<div className="flex space-x-2">
<div className="flex flex-col items-center justify-start">
<span className="text-lg">SEM</span>
<span className="text-2xl font-bold ">
{semester.semesterNumber}
</span>
</div>
</div>
</div>
<div className="w-full items-end flex flex-col mt-2 *:pl-6">
<div className="flex justify-between w-full mb-2 items-center">
<select
value={semester.semesterSeason}
onChange={seasonDropdown}
className="border-1 border-black rounded-full px-3 py-0 h-fit w-auto font-medium text-sm "
>
{seasons.map((season) => (
<option key={season} value={season}>
{season}
</option>
))}
</select>
<div className="text-lg ">
<span className="font-bold">credits:</span>{" "}
{semester.creditsTotal}
</div>
</div>
<Droppable droppableId={`planner-${index}`} direction="vertical">
{(provided, snapshot) => {
const isEmpty = semester.courseList.length === 0;
const isHovering = snapshot.isDraggingOver;
return (
<div
ref={provided.innerRef}
{...provided.droppableProps}
className="flex flex-col space-y-2 w-full"
>
{isEmpty && !isHovering && (
<PlannerCourseHolder isHover={false} />
)}
{isEmpty && isHovering && (
<PlannerCourseHolder isHover={true} />
)}
{!isEmpty &&
semester.courseList.map((course, courseIndex) => (
<DraggableItem
key={course.name}
name={course.name}
course={course.data}
count={course.count}
index={courseIndex}
semesterIndex={index}
setPlannerCourses={setPlannerCourses}
setToolboxCourses={setToolboxCourses}
location="planner"
/>
))}
{provided.placeholder}
</div>
);
}}
</Droppable>
</div>
</div>
</>
);
};
export default SemesterBlock;