Skip to content

Commit e214b90

Browse files
committed
docked courses get added into degree plan when added to semesters
1 parent af9f38d commit e214b90

File tree

2 files changed

+38
-33
lines changed

2 files changed

+38
-33
lines changed

frontend/degree-plan/components/Dock/Dock.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ const Logo = styled.img`
9292
const AnimatedDockedCourseItem = styled(CourseInDock)`
9393
z-index: 1000;
9494
background: var(--background-grey);
95-
animation-name: jump;
96-
animation-duration: 1.5s;
97-
animation-iteration-count: 1;
98-
animation-timing-function: linear;
95+
// animation-name: jump;
96+
// animation-duration: 1.5s;
97+
// animation-iteration-count: 1;
98+
// animation-timing-function: linear;
9999
`
100100

101101
interface DockProps {

frontend/degree-plan/components/FourYearPlan/Semester.tsx

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -148,40 +148,45 @@ const FlexSemester = ({
148148

149149
const [{ isOver, canDrop }, drop] = useDrop<DnDCourse, never, { isOver: boolean, canDrop: boolean }>(() => ({
150150
accept: [ItemTypes.COURSE_IN_PLAN, ItemTypes.COURSE_IN_DOCK, ItemTypes.COURSE_IN_REQ, ItemTypes.COURSE_IN_SEARCH],
151-
drop: (course: DnDCourse) => {
152-
if (course.rule_id === undefined || course.rule_id == null) { // moved from plan or dock
151+
drop: (course: DnDCourse, monitor) => {
152+
const itemType = monitor.getItemType();
153+
if (itemType === ItemTypes.COURSE_IN_PLAN) { // moved from plan or dock
153154
createOrUpdate({ semester }, course.full_code);
154-
} else { // moved from req panel
155-
fetch(`/api/degree/satisfied-rule-list/${activeDegreeplanId}/${course.full_code}/${course.rule_id}`).then((r) => {
156-
r.json().then((data) => {
157-
const selectedRules = data["selected_rules"].reduce((res: any, obj: any) => {
158-
res.push(obj.id);
159-
return res;
160-
}, []);
161-
const unselectedRules = data["unselected_rules"].reduce((res: any, obj: any) => {
162-
res.push(obj.id);
163-
return res;
164-
}, []);
165-
166-
createOrUpdate({
167-
rules: selectedRules,
168-
unselected_rules: unselectedRules,
169-
legal: data.legal,
170-
semester
171-
}, course.full_code);
155+
return;
156+
}
157+
if (itemType === ItemTypes.COURSE_IN_DOCK) {
158+
course.rule_id = -1;
159+
}
160+
fetch(`/api/degree/satisfied-rule-list/${activeDegreeplanId}/${course.full_code}/${course.rule_id}`).then((r) => {
161+
r.json().then((data) => {
162+
const selectedRules = data["selected_rules"].reduce((res: any, obj: any) => {
163+
res.push(obj.id);
164+
return res;
165+
}, []);
166+
const unselectedRules = data["unselected_rules"].reduce((res: any, obj: any) => {
167+
res.push(obj.id);
168+
return res;
169+
}, []);
170+
171+
createOrUpdate({
172+
rules: selectedRules,
173+
unselected_rules: unselectedRules,
174+
legal: data.legal,
175+
semester
176+
}, course.full_code);
172177

173-
// Toast only if course has been directly dragged from search (not reqpanel!)
174-
// TODO: This doesn't work for explicitly listed courses.
178+
// Toast only if course has been directly dragged from search (not reqpanel!)
179+
// TODO: This doesn't work for explicitly listed courses.
175180

176-
for (let obj of data["new_selected_rules"]) {
177-
if (obj.id != course.rule_id) {
178-
showToast(`${course.full_code} also fulfilled ${obj.title}!`, false);
179-
}
181+
for (let obj of data["new_selected_rules"]) {
182+
if (course.rule_id === -1) {
183+
showToast(`${course.full_code} fulfilled ${obj.title}!`, false);
184+
} else if (obj.id != course.rule_id) {
185+
showToast(`${course.full_code} also fulfilled ${obj.title}!`, false);
180186
}
181-
})
187+
}
182188
})
183-
}
184-
189+
})
185190
return undefined;
186191
},
187192
collect: monitor => ({

0 commit comments

Comments
 (0)