From d47e5527898d8bd8eeafc4c0d3a454744758f370 Mon Sep 17 00:00:00 2001 From: Srikavin Ramkumar Date: Tue, 25 Jul 2023 14:35:31 -0400 Subject: [PATCH] restructure packages --- {functions/src => common}/types.ts | 0 .../screens/HistoryScreen/HistoryScreen.tsx | 26 ++++++++++++------- frontend/tsconfig.json | 12 ++++----- functions/src/notifier/discord.ts | 2 +- functions/src/notifier/send.ts | 2 +- functions/src/scraper/generate_events.ts | 2 +- functions/tsconfig.json | 5 ++++ package.json | 13 ++++++++++ util/tsconfig.json | 5 ++++ web/tsconfig.json | 5 ++++ 10 files changed, 53 insertions(+), 19 deletions(-) rename {functions/src => common}/types.ts (100%) create mode 100644 package.json diff --git a/functions/src/types.ts b/common/types.ts similarity index 100% rename from functions/src/types.ts rename to common/types.ts diff --git a/frontend/src/screens/HistoryScreen/HistoryScreen.tsx b/frontend/src/screens/HistoryScreen/HistoryScreen.tsx index 99aa088..dac8915 100644 --- a/frontend/src/screens/HistoryScreen/HistoryScreen.tsx +++ b/frontend/src/screens/HistoryScreen/HistoryScreen.tsx @@ -12,9 +12,10 @@ import {AddToSchedule} from "../../components/AddToSchedule/AddToSchedule"; import {useCourseEvents} from "../../util/useCourseEvents"; import {countWatchersFunction} from "../../firebase"; import {UserSubscriptionsContext} from "../../context/UserSubscriptions"; +import {CourseEvent} from "@/common/types"; interface FormattedCourseEventProps { - event: object + event: CourseEvent } function MeetingTimeChanged(props: { event_data: any }) { @@ -25,7 +26,7 @@ function MeetingTimeChanged(props: { event_data: any }) { )); } -const nameMapping: Record = { +const nameMapping: Record = { 'course_added': 'Course added', 'section_added': 'Section added', 'course_removed': 'Course removed', @@ -38,13 +39,12 @@ const nameMapping: Record = { 'waitlist_changed': 'Waitlist changed', 'holdfile_changed': 'Holdfile changed', 'course_description_changed': 'Course description changed', - 'meeting_times_changed': 'Meeting times changed' + 'meeting_times_changed': 'Meeting times changed', + 'test_notification': '' } export function FormattedCourseEvent(props: FormattedCourseEventProps) { - const {event} = props as any; - - // if () return null; + const {event} = props; if (!(event.type in nameMapping)) { return ( @@ -65,23 +65,27 @@ export function FormattedCourseEvent(props: FormattedCourseEventProps) { {event.type !== 'open_seat_available' && ( <> + {/* @ts-ignore */} {event.old !== undefined && ( <> from
                         {event.type === 'meeting_times_changed' ? (
                             
                         ) : (
+                            /* @ts-ignore */
                             <>'{event.old}'
                         )}
                     
)} + {/* @ts-ignore */} {event.new !== undefined && ( <> to
                     {event.type === 'meeting_times_changed' ? (
                         
                     ) : (
+                        /* @ts-ignore */
                         <>'{event.new}'
                     )}
                     
@@ -95,7 +99,7 @@ export function FormattedCourseEvent(props: FormattedCourseEventProps) { } -function FormattedCourseEvents(props: { events: Array }) { +function FormattedCourseEvents(props: { events: Array }) { const {events} = props; const grouped = []; @@ -112,12 +116,13 @@ function FormattedCourseEvents(props: { events: Array }) { return ( <> {grouped.flatMap(x => { + const firstEvent = x[0] if (x.length == 1) { return [ - + ] } - if (['total_seats_changed', 'waitlist_changed', 'holdfile_changed', 'open_seats_changed'].includes(x[0].type)) { + if (firstEvent.type === 'total_seats_changed' || firstEvent.type === 'waitlist_changed' || firstEvent.type === 'holdfile_changed' || firstEvent.type === 'open_seats_changed') { return [
@@ -128,7 +133,8 @@ function FormattedCourseEvents(props: { events: Array }) { {dayjs(x[x.length - 1].timestamp).format("MM-DD-YYYY HH:mm")} -

{nameMapping[x[0].type]} from {x[x.length - 1].old} to {x[0].new}

+ {/* @ts-ignore */} +

{nameMapping[firstEvent.type]} from {x[x.length - 1].old} to {firstEvent.new}

{ return { diff --git a/functions/src/notifier/send.ts b/functions/src/notifier/send.ts index 0cc6c95..a125eda 100644 --- a/functions/src/notifier/send.ts +++ b/functions/src/notifier/send.ts @@ -7,7 +7,7 @@ import { webhookQueueShardCount } from "../common"; import {getDiscordContent} from "./discord"; -import {CourseEvent} from "../types"; +import {CourseEvent} from "@/common/types"; import * as webpush from "web-push"; import {PushSubscription} from "web-push"; diff --git a/functions/src/scraper/generate_events.ts b/functions/src/scraper/generate_events.ts index 5bb8f41..4eac0ce 100644 --- a/functions/src/scraper/generate_events.ts +++ b/functions/src/scraper/generate_events.ts @@ -1,5 +1,5 @@ import * as crypto from "crypto"; -import {CourseEvent} from "../types"; +import {CourseEvent} from "@/common/types"; import {ScrapedCourse, ScrapedOutput, ScrapedSection} from "./scraper"; function toOrderedString(obj: any) { diff --git a/functions/tsconfig.json b/functions/tsconfig.json index 933ec6e..473596b 100644 --- a/functions/tsconfig.json +++ b/functions/tsconfig.json @@ -1,5 +1,10 @@ { "compilerOptions": { + "paths": { + "@/*": [ + "../*" + ] + }, "module": "commonjs", "noImplicitReturns": true, "noUnusedLocals": true, diff --git a/package.json b/package.json new file mode 100644 index 0000000..3afb64f --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "waitlist-watcher", + "version": "1.0.0", + "description": "Get notified of changes to courses", + "workspaces": [ + "frontend", + "functions", + "scripts", + "web" + ], + "dependencies": { + } +} diff --git a/util/tsconfig.json b/util/tsconfig.json index 74b5a0b..2449703 100644 --- a/util/tsconfig.json +++ b/util/tsconfig.json @@ -1,5 +1,10 @@ { "compilerOptions": { + "paths": { + "@/*": [ + "../*" + ] + }, "lib": [ "es2021" ], diff --git a/web/tsconfig.json b/web/tsconfig.json index 044b77e..306ca25 100644 --- a/web/tsconfig.json +++ b/web/tsconfig.json @@ -1,5 +1,10 @@ { "compilerOptions": { + "paths": { + "@/*": [ + "../*" + ] + }, "lib": ["es2021"], "module": "commonjs", "target": "es2021",