From 302989f615a172e20b171e27a0bccd36244a099e Mon Sep 17 00:00:00 2001 From: Kevin Wu Date: Fri, 24 Nov 2023 23:29:22 -0800 Subject: [PATCH 01/12] Create snackbar when schedules are copied over --- apps/antalmanac/src/actions/AppStoreActions.ts | 10 ++++++++-- .../RightPane/AddedCourses/AddedCoursePane.tsx | 10 ++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/apps/antalmanac/src/actions/AppStoreActions.ts b/apps/antalmanac/src/actions/AppStoreActions.ts index 8caab3f47..0e965d1c7 100644 --- a/apps/antalmanac/src/actions/AppStoreActions.ts +++ b/apps/antalmanac/src/actions/AppStoreActions.ts @@ -182,13 +182,19 @@ export const changeCourseColor = (sectionCode: string, term: string, newColor: s AppStore.changeCourseColor(sectionCode, term, newColor); }; -export const copySchedule = (to: number) => { +export const copySchedule = (name: string, to: number) => { logAnalytics({ category: analyticsEnum.addedClasses.title, action: analyticsEnum.addedClasses.actions.COPY_SCHEDULE, }); - AppStore.copySchedule(to); + try { + AppStore.copySchedule(to); + } catch (error) { + openSnackbar('error', `Could not copy schedule to ${name}.`); + } + + openSnackbar('success', `Schedule copied to ${name}.`); }; export const toggleTheme = (radioGroupEvent: React.ChangeEvent) => { diff --git a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx index bebb71fce..6c7aa92f8 100644 --- a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx +++ b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx @@ -100,9 +100,9 @@ function handleClear() { } } -function createCopyHandler(index: number) { +function createCopyHandler(name: string, index: number) { return () => { - copySchedule(index); + copySchedule(name, index); }; } @@ -148,12 +148,14 @@ function CopyScheduleButton() { Copy to {name} ))} - Copy to All Schedules + + Copy to All Schedules + )} From 210a835c393a42cf1009c72b0c8195bdf9e8808e Mon Sep 17 00:00:00 2001 From: Kevin Wu Date: Fri, 24 Nov 2023 23:32:32 -0800 Subject: [PATCH 02/12] Correct snackbar call --- apps/antalmanac/src/actions/AppStoreActions.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/antalmanac/src/actions/AppStoreActions.ts b/apps/antalmanac/src/actions/AppStoreActions.ts index 0e965d1c7..622657cbd 100644 --- a/apps/antalmanac/src/actions/AppStoreActions.ts +++ b/apps/antalmanac/src/actions/AppStoreActions.ts @@ -190,11 +190,10 @@ export const copySchedule = (name: string, to: number) => { try { AppStore.copySchedule(to); + openSnackbar('success', `Schedule copied to ${name}.`); } catch (error) { openSnackbar('error', `Could not copy schedule to ${name}.`); } - - openSnackbar('success', `Schedule copied to ${name}.`); }; export const toggleTheme = (radioGroupEvent: React.ChangeEvent) => { From e7b1cc0f6db65cfd372e278626813a82504fefc2 Mon Sep 17 00:00:00 2001 From: Kevin Wu Date: Sat, 2 Dec 2023 10:25:21 -0800 Subject: [PATCH 03/12] Use callbacks --- .../antalmanac/src/actions/AppStoreActions.ts | 11 ++++++++--- .../AddedCourses/AddedCoursePane.tsx | 19 ++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/apps/antalmanac/src/actions/AppStoreActions.ts b/apps/antalmanac/src/actions/AppStoreActions.ts index 622657cbd..1999af7fd 100644 --- a/apps/antalmanac/src/actions/AppStoreActions.ts +++ b/apps/antalmanac/src/actions/AppStoreActions.ts @@ -12,6 +12,11 @@ import AppStore from '$stores/AppStore'; import trpc from '$lib/api/trpc'; import { courseNumAsDecimal } from '$lib/analytics'; +export interface CallbackOptions { + onSuccess: (name?: string) => unknown; + onError: (name?: string) => unknown; +} + export const addCourse = ( section: WebsocSection, courseDetails: CourseDetails, @@ -182,7 +187,7 @@ export const changeCourseColor = (sectionCode: string, term: string, newColor: s AppStore.changeCourseColor(sectionCode, term, newColor); }; -export const copySchedule = (name: string, to: number) => { +export const copySchedule = (name: string, to: number, options?: CallbackOptions) => { logAnalytics({ category: analyticsEnum.addedClasses.title, action: analyticsEnum.addedClasses.actions.COPY_SCHEDULE, @@ -190,9 +195,9 @@ export const copySchedule = (name: string, to: number) => { try { AppStore.copySchedule(to); - openSnackbar('success', `Schedule copied to ${name}.`); + options?.onSuccess(name); } catch (error) { - openSnackbar('error', `Could not copy schedule to ${name}.`); + options?.onError(name); } }; diff --git a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx index 6c7aa92f8..1d3d5810c 100644 --- a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx +++ b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx @@ -17,12 +17,13 @@ import { import { ContentCopy, DeleteOutline } from '@mui/icons-material'; import { AACourse } from '@packages/antalmanac-types'; +import { useSnackbar } from 'notistack'; import { ColumnToggleButton } from '../CoursePane/CoursePaneButtonRow'; import SectionTableLazyWrapper from '../SectionTable/SectionTableLazyWrapper'; import CustomEventDetailView from './CustomEventDetailView'; import AppStore from '$stores/AppStore'; import analyticsEnum, { logAnalytics } from '$lib/analytics'; -import { clearSchedules, copySchedule, updateScheduleNote } from '$actions/AppStoreActions'; +import { CallbackOptions, clearSchedules, copySchedule, updateScheduleNote } from '$actions/AppStoreActions'; import { clickToCopy } from '$lib/helpers'; /** @@ -100,9 +101,9 @@ function handleClear() { } } -function createCopyHandler(name: string, index: number) { +function createCopyHandler(name: string, index: number, options: CallbackOptions) { return () => { - copySchedule(name, index); + copySchedule(name, index, options); }; } @@ -118,6 +119,14 @@ function ClearScheduleButton() { function CopyScheduleButton() { const [scheduleNames, setScheduleNames] = useState(AppStore.getScheduleNames()); + const { enqueueSnackbar } = useSnackbar(); + + const options = useMemo(() => { + return { + onSuccess: (name?: string) => enqueueSnackbar(`Schedule copied to ${name}.`, { variant: 'success' }), + onError: (name?: string) => enqueueSnackbar(`Could not copy schedule to ${name}.`, { variant: 'error' }), + }; + }, [enqueueSnackbar]); useEffect(() => { /** @@ -148,12 +157,12 @@ function CopyScheduleButton() { Copy to {name} ))} - + Copy to All Schedules From 359717bd0364c1305099d72f8cd2d54da715cf58 Mon Sep 17 00:00:00 2001 From: Kevin Wu Date: Sun, 3 Dec 2023 17:32:43 -0800 Subject: [PATCH 04/12] Update apps/antalmanac/src/actions/AppStoreActions.ts Co-authored-by: Aponia --- apps/antalmanac/src/actions/AppStoreActions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/antalmanac/src/actions/AppStoreActions.ts b/apps/antalmanac/src/actions/AppStoreActions.ts index 1999af7fd..258e5b095 100644 --- a/apps/antalmanac/src/actions/AppStoreActions.ts +++ b/apps/antalmanac/src/actions/AppStoreActions.ts @@ -13,8 +13,8 @@ import trpc from '$lib/api/trpc'; import { courseNumAsDecimal } from '$lib/analytics'; export interface CallbackOptions { - onSuccess: (name?: string) => unknown; - onError: (name?: string) => unknown; + onSuccess: (index: number) => unknown; + onError: (index: number) => unknown; } export const addCourse = ( From 0d1548dc0eebc0db00c0af3423719317c1c27399 Mon Sep 17 00:00:00 2001 From: Kevin Wu Date: Sun, 3 Dec 2023 17:32:50 -0800 Subject: [PATCH 05/12] Update apps/antalmanac/src/actions/AppStoreActions.ts Co-authored-by: Aponia --- apps/antalmanac/src/actions/AppStoreActions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/antalmanac/src/actions/AppStoreActions.ts b/apps/antalmanac/src/actions/AppStoreActions.ts index 258e5b095..0e5da7be3 100644 --- a/apps/antalmanac/src/actions/AppStoreActions.ts +++ b/apps/antalmanac/src/actions/AppStoreActions.ts @@ -195,9 +195,9 @@ export const copySchedule = (name: string, to: number, options?: CallbackOptions try { AppStore.copySchedule(to); - options?.onSuccess(name); + options?.onSuccess(to); } catch (error) { - options?.onError(name); + options?.onError(to); } }; From 6835e4bc0953a34e4b36ff6a56caae40698765a3 Mon Sep 17 00:00:00 2001 From: Kevin Wu Date: Sun, 3 Dec 2023 17:32:55 -0800 Subject: [PATCH 06/12] Update apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx Co-authored-by: Aponia --- .../src/components/RightPane/AddedCourses/AddedCoursePane.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx index 1d3d5810c..c109bceec 100644 --- a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx +++ b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx @@ -157,7 +157,7 @@ function CopyScheduleButton() { Copy to {name} From 9d8d6c8581dccd332c38c004ce4c64dfa4ee0a2d Mon Sep 17 00:00:00 2001 From: Kevin Wu Date: Sun, 3 Dec 2023 17:33:01 -0800 Subject: [PATCH 07/12] Update apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx Co-authored-by: Aponia --- .../src/components/RightPane/AddedCourses/AddedCoursePane.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx index c109bceec..475731504 100644 --- a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx +++ b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx @@ -123,8 +123,8 @@ function CopyScheduleButton() { const options = useMemo(() => { return { - onSuccess: (name?: string) => enqueueSnackbar(`Schedule copied to ${name}.`, { variant: 'success' }), - onError: (name?: string) => enqueueSnackbar(`Could not copy schedule to ${name}.`, { variant: 'error' }), + onSuccess: (index: number) => enqueueSnackbar(`Schedule copied to ${scheduleNames[index]}.`, { variant: 'success' }), + onError: (index: number) => enqueueSnackbar(`Could not copy schedule to ${scheduleNames[index]}.`, { variant: 'error' }), }; }, [enqueueSnackbar]); From 50b5f7243d43507e81b5ed0d42565d07e7e4bf45 Mon Sep 17 00:00:00 2001 From: Kevin Wu Date: Sun, 3 Dec 2023 17:33:08 -0800 Subject: [PATCH 08/12] Update apps/antalmanac/src/actions/AppStoreActions.ts Co-authored-by: Aponia --- apps/antalmanac/src/actions/AppStoreActions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/antalmanac/src/actions/AppStoreActions.ts b/apps/antalmanac/src/actions/AppStoreActions.ts index 0e5da7be3..4d2dca3a7 100644 --- a/apps/antalmanac/src/actions/AppStoreActions.ts +++ b/apps/antalmanac/src/actions/AppStoreActions.ts @@ -12,7 +12,7 @@ import AppStore from '$stores/AppStore'; import trpc from '$lib/api/trpc'; import { courseNumAsDecimal } from '$lib/analytics'; -export interface CallbackOptions { +export interface CopyScheduleOptions { onSuccess: (index: number) => unknown; onError: (index: number) => unknown; } From d4bec224b7a79be9c7f37a7680240a3153f35220 Mon Sep 17 00:00:00 2001 From: Kevin Wu Date: Sun, 3 Dec 2023 17:51:29 -0800 Subject: [PATCH 09/12] Update apps/antalmanac/src/actions/AppStoreActions.ts Co-authored-by: Aponia --- apps/antalmanac/src/actions/AppStoreActions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/antalmanac/src/actions/AppStoreActions.ts b/apps/antalmanac/src/actions/AppStoreActions.ts index 4d2dca3a7..68d2ff9ab 100644 --- a/apps/antalmanac/src/actions/AppStoreActions.ts +++ b/apps/antalmanac/src/actions/AppStoreActions.ts @@ -187,7 +187,7 @@ export const changeCourseColor = (sectionCode: string, term: string, newColor: s AppStore.changeCourseColor(sectionCode, term, newColor); }; -export const copySchedule = (name: string, to: number, options?: CallbackOptions) => { +export const copySchedule = (to: number, options?: CallbackOptions) => { logAnalytics({ category: analyticsEnum.addedClasses.title, action: analyticsEnum.addedClasses.actions.COPY_SCHEDULE, From 500baaf248eac999da105471b24b21f6131368c0 Mon Sep 17 00:00:00 2001 From: Kevin Wu Date: Sun, 3 Dec 2023 17:56:46 -0800 Subject: [PATCH 10/12] Clean up refactoringt --- .../antalmanac/src/actions/AppStoreActions.ts | 2 +- .../AddedCourses/AddedCoursePane.tsx | 24 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/apps/antalmanac/src/actions/AppStoreActions.ts b/apps/antalmanac/src/actions/AppStoreActions.ts index 68d2ff9ab..eb937ef40 100644 --- a/apps/antalmanac/src/actions/AppStoreActions.ts +++ b/apps/antalmanac/src/actions/AppStoreActions.ts @@ -187,7 +187,7 @@ export const changeCourseColor = (sectionCode: string, term: string, newColor: s AppStore.changeCourseColor(sectionCode, term, newColor); }; -export const copySchedule = (to: number, options?: CallbackOptions) => { +export const copySchedule = (to: number, options?: CopyScheduleOptions) => { logAnalytics({ category: analyticsEnum.addedClasses.title, action: analyticsEnum.addedClasses.actions.COPY_SCHEDULE, diff --git a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx index 475731504..2890587c4 100644 --- a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx +++ b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx @@ -23,7 +23,7 @@ import SectionTableLazyWrapper from '../SectionTable/SectionTableLazyWrapper'; import CustomEventDetailView from './CustomEventDetailView'; import AppStore from '$stores/AppStore'; import analyticsEnum, { logAnalytics } from '$lib/analytics'; -import { CallbackOptions, clearSchedules, copySchedule, updateScheduleNote } from '$actions/AppStoreActions'; +import { CopyScheduleOptions, clearSchedules, copySchedule, updateScheduleNote } from '$actions/AppStoreActions'; import { clickToCopy } from '$lib/helpers'; /** @@ -101,9 +101,9 @@ function handleClear() { } } -function createCopyHandler(name: string, index: number, options: CallbackOptions) { +function createCopyHandler(index: number, options: CopyScheduleOptions) { return () => { - copySchedule(name, index, options); + copySchedule(index, options); }; } @@ -123,10 +123,20 @@ function CopyScheduleButton() { const options = useMemo(() => { return { - onSuccess: (index: number) => enqueueSnackbar(`Schedule copied to ${scheduleNames[index]}.`, { variant: 'success' }), - onError: (index: number) => enqueueSnackbar(`Could not copy schedule to ${scheduleNames[index]}.`, { variant: 'error' }), + onSuccess: (index: number) => + enqueueSnackbar( + `Schedule copied to ${index === scheduleNames.length ? 'All Schedules' : scheduleNames[index]}.`, + { variant: 'success' } + ), + onError: (index: number) => + enqueueSnackbar( + `Could not copy schedule to ${ + index === scheduleNames.length ? 'All Schedules' : scheduleNames[index] + }.`, + { variant: 'error' } + ), }; - }, [enqueueSnackbar]); + }, [enqueueSnackbar, scheduleNames]); useEffect(() => { /** @@ -162,7 +172,7 @@ function CopyScheduleButton() { Copy to {name} ))} - + Copy to All Schedules From d323771a0db853d0e96ea7bc5dbbf53a5c15488b Mon Sep 17 00:00:00 2001 From: Aponia Date: Sun, 3 Dec 2023 17:59:12 -0800 Subject: [PATCH 11/12] style: calculate name on a separate line --- .../AddedCourses/AddedCoursePane.tsx | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx index 2890587c4..e4eb048ea 100644 --- a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx +++ b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx @@ -123,18 +123,14 @@ function CopyScheduleButton() { const options = useMemo(() => { return { - onSuccess: (index: number) => - enqueueSnackbar( - `Schedule copied to ${index === scheduleNames.length ? 'All Schedules' : scheduleNames[index]}.`, - { variant: 'success' } - ), - onError: (index: number) => - enqueueSnackbar( - `Could not copy schedule to ${ - index === scheduleNames.length ? 'All Schedules' : scheduleNames[index] - }.`, - { variant: 'error' } - ), + onSuccess: (index: number) => { + const name = index === scheduleNames.length ? 'All Schedules' : scheduleNames[index]; + enqueueSnackbar(`Schedule copied to ${name}.`, { variant: 'success' }); + }, + onError: (index: number) => { + const name = index === scheduleNames.length ? 'All Schedules' : scheduleNames[index]; + enqueueSnackbar(`Could not copy schedule to ${name}.`, { variant: 'error' }); + }, }; }, [enqueueSnackbar, scheduleNames]); From f0ed58acc58897538ee4208d2896d7a3f695b3e7 Mon Sep 17 00:00:00 2001 From: Kevin Wu Date: Sun, 3 Dec 2023 18:05:28 -0800 Subject: [PATCH 12/12] noop