Skip to content

Commit

Permalink
[CPM-202] Remove courses from dropdown as they're added to a regulati…
Browse files Browse the repository at this point in the history
…on (#145)

* clean up api client code

* fix crash when exporting plan with empty notes

* make spacing consistend, update snapshots

* remove courses from dropdown as they're added to a regulation

* rename c to course

* update timeout to 5000

Co-authored-by: dinith1 <[email protected]>
  • Loading branch information
Dinith1 and Dinith1 authored Oct 14, 2020
1 parent c114420 commit f9ae956
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions api/src/uni-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const fetchAllCourses = async (subject, year) => {
() => {
controller.abort();
},
2000,
5000,
);

try {
Expand All @@ -39,7 +39,7 @@ const fetchParticularCourse = async (subject, catalogNbr, year) => {
() => {
controller.abort();
},
2000,
5000,
);

try {
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/Plan/usePlan.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const usePlan = () => {
const [lastSaveDate, setLastSaveDate] = useState(new Date());

const initPage = useCallback(async () => {
// Promise.all because we are going to have a lot of API calls once requirements/courses/notes come in !
// Promise.all because we are going to have a lot of API calls once requirements/courses/notes come in!
Promise.all([CoursePlannerClient.getCourses(), CoursePlannerClient.getPlan(planId)])
.then(([courses, plan]) => {
setCourses(courses);
Expand Down
12 changes: 4 additions & 8 deletions client/src/pages/Programmes/InlineRegulations.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ const InlineRegulations = ({ closeEdit, programme, notifyUpdate, regulation }) =
const [points, setPoints] = useState(15);
const [pointRequirement, setPointRequirement] = useState("EXACTLY");

const handleAddCourse = (course) => {
if (!courses.includes(course)) {
setCourses((oldCourses) => [course, ...oldCourses]);
}
};

const handleRemoveCourse = (courseId) => {
const filteredCourses = courses.filter((course) => course._id !== courseId);
setCourses(filteredCourses);
Expand Down Expand Up @@ -126,8 +120,10 @@ const InlineRegulations = ({ closeEdit, programme, notifyUpdate, regulation }) =
{/* Course Dropdown */}
<Flex direction="row" width="55%" align="center">
<SingleSelect
onChange={(course) => handleAddCourse(course)}
data={data.map((course) => ({ value: course, label: course.courseCode }))}
onChange={(course) => setCourses([...courses, course])}
data={data
.filter((course) => !courses.includes(course))
.map((course) => ({ value: course, label: course.courseCode }))}
placeholder="Search"
/>
<Flex
Expand Down

0 comments on commit f9ae956

Please sign in to comment.