From 7c9c72713589fb54ed80ace9801fd7e019bda6b5 Mon Sep 17 00:00:00 2001 From: HosokawaR Date: Sat, 1 Apr 2023 15:49:15 +0000 Subject: [PATCH 1/3] Fix bug in schedule conflict check in adding courses --- src/ui/pages/add/search.vue | 13 ++++++------- src/utils.ts | 8 ++++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/ui/pages/add/search.vue b/src/ui/pages/add/search.vue index df2178a1..abadc239 100644 --- a/src/ui/pages/add/search.vue +++ b/src/ui/pages/add/search.vue @@ -287,7 +287,7 @@ import ToggleButton from "~/ui/components/ToggleButton.vue"; import { useSwitch } from "~/ui/hooks/useSwitch"; import { addCoursesByCodes } from "~/ui/store/course"; import { getApplicableYear } from "~/ui/store/year"; -import { deleteElementInArray } from "~/utils"; +import { asyncFilter, deleteElementInArray } from "~/utils"; import type { Schedule } from "~/domain/schedule"; import type { DisplayCourse } from "~/presentation/viewmodels/course"; @@ -472,12 +472,11 @@ const buttonState = computed(() => const duplicateCourses = ref([]); const addCourses = async (warning = true) => { - duplicateCourses.value = ( - await Promise.all( - selectedSearchResults.filter( - ({ schedules }) => - !Usecase.checkScheduleDuplicate(ports)(year.value, schedules) - ) + duplicateCourses.value = await ( + await asyncFilter( + selectedSearchResults, + async ({ schedules }) => + !(await Usecase.checkScheduleDuplicate(ports)(year.value, schedules)) ) ).map(({ course }) => course); diff --git a/src/utils.ts b/src/utils.ts index 611f7616..1ff06ac0 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -133,3 +133,11 @@ export const hasProperty =

( ): obj is { [key in P]: T } => { return hasUnknownProperty(obj, prop) && clarifyPropertyType(obj, prop, fn); }; + +export const asyncFilter = async ( + array: T[], + asyncCallback: (arg: T) => Promise +) => { + const mask = await Promise.all(array.map(asyncCallback)); + return array.filter((_, i) => Boolean(mask[i])); +}; From 45fb9e3069ca5e2b92d86021ef6216af73e3b606 Mon Sep 17 00:00:00 2001 From: HosokawaR Date: Sun, 2 Apr 2023 02:44:55 +0000 Subject: [PATCH 2/3] Add toast to notify error when the already registered course has been added --- src/ui/pages/add/search.vue | 33 ++++++++++++++++++++++++++++++--- src/ui/store/toast.ts | 2 +- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/ui/pages/add/search.vue b/src/ui/pages/add/search.vue index abadc239..3d3826fb 100644 --- a/src/ui/pages/add/search.vue +++ b/src/ui/pages/add/search.vue @@ -194,7 +194,7 @@