From f9ae95607fa445208145f39dada553ee2cb2af4a Mon Sep 17 00:00:00 2001 From: Dinith <34013038+Dinith1@users.noreply.github.com> Date: Wed, 14 Oct 2020 23:47:28 +1300 Subject: [PATCH] [CPM-202] Remove courses from dropdown as they're added to a regulation (#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 --- api/src/uni-service.js | 4 ++-- client/src/pages/Plan/usePlan.js | 2 +- client/src/pages/Programmes/InlineRegulations.js | 12 ++++-------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/api/src/uni-service.js b/api/src/uni-service.js index 60ba4419..339a0edb 100644 --- a/api/src/uni-service.js +++ b/api/src/uni-service.js @@ -15,7 +15,7 @@ const fetchAllCourses = async (subject, year) => { () => { controller.abort(); }, - 2000, + 5000, ); try { @@ -39,7 +39,7 @@ const fetchParticularCourse = async (subject, catalogNbr, year) => { () => { controller.abort(); }, - 2000, + 5000, ); try { diff --git a/client/src/pages/Plan/usePlan.js b/client/src/pages/Plan/usePlan.js index 2ed2e419..b9c8dd02 100644 --- a/client/src/pages/Plan/usePlan.js +++ b/client/src/pages/Plan/usePlan.js @@ -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); diff --git a/client/src/pages/Programmes/InlineRegulations.js b/client/src/pages/Programmes/InlineRegulations.js index e8410c1c..1bf7cf7e 100644 --- a/client/src/pages/Programmes/InlineRegulations.js +++ b/client/src/pages/Programmes/InlineRegulations.js @@ -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); @@ -126,8 +120,10 @@ const InlineRegulations = ({ closeEdit, programme, notifyUpdate, regulation }) = {/* Course Dropdown */} 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" />