Skip to content

Commit

Permalink
restructure packages
Browse files Browse the repository at this point in the history
  • Loading branch information
srikavin committed Jul 25, 2023
1 parent 7fb2c3e commit 7de25d3
Show file tree
Hide file tree
Showing 12 changed files with 9,596 additions and 20 deletions.
File renamed without changes.
26 changes: 16 additions & 10 deletions frontend/src/screens/HistoryScreen/HistoryScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand All @@ -25,7 +26,7 @@ function MeetingTimeChanged(props: { event_data: any }) {
));
}

const nameMapping: Record<string, string> = {
const nameMapping: Record<CourseEvent['type'], string> = {
'course_added': 'Course added',
'section_added': 'Section added',
'course_removed': 'Course removed',
Expand All @@ -38,13 +39,12 @@ const nameMapping: Record<string, string> = {
'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 (
Expand All @@ -65,23 +65,27 @@ export function FormattedCourseEvent(props: FormattedCourseEventProps) {
</span>
{event.type !== 'open_seat_available' && (
<>
{/* @ts-ignore */}
{event.old !== undefined && (
<> from <s>
<pre className={styles.old + " inline"}>
{event.type === 'meeting_times_changed' ? (
<MeetingTimeChanged event_data={event.old}/>
) : (
/* @ts-ignore */
<>'{event.old}'</>
)}
</pre>
</s>
</>
)}
{/* @ts-ignore */}
{event.new !== undefined && (
<> to <pre className={styles.new + " inline"}>
{event.type === 'meeting_times_changed' ? (
<MeetingTimeChanged event_data={event.new}/>
) : (
/* @ts-ignore */
<>'{event.new}'</>
)}
</pre>
Expand All @@ -95,7 +99,7 @@ export function FormattedCourseEvent(props: FormattedCourseEventProps) {
}


function FormattedCourseEvents(props: { events: Array<any> }) {
function FormattedCourseEvents(props: { events: Array<CourseEvent> }) {
const {events} = props;

const grouped = [];
Expand All @@ -112,12 +116,13 @@ function FormattedCourseEvents(props: { events: Array<any> }) {
return (
<>
{grouped.flatMap(x => {
const firstEvent = x[0]
if (x.length == 1) {
return [
<FormattedCourseEvent event={x[0]} key={x[0].id}/>
<FormattedCourseEvent event={firstEvent} key={firstEvent.id}/>
]
}
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 [
<details>
<summary className="list-outside">
Expand All @@ -128,7 +133,8 @@ function FormattedCourseEvents(props: { events: Array<any> }) {
<small
className="block">{dayjs(x[x.length - 1].timestamp).format("MM-DD-YYYY HH:mm")}</small>
</div>
<p className="place-self-center">{nameMapping[x[0].type]} from {x[x.length - 1].old} to {x[0].new}</p>
{/* @ts-ignore */}
<p className="place-self-center">{nameMapping[firstEvent.type]} from {x[x.length - 1].old} to {firstEvent.new}</p>
</div>
</summary>
<Pane display="flex" flexDirection="column" gap={0} paddingLeft={12} marginLeft={4}
Expand Down
12 changes: 6 additions & 6 deletions frontend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"compilerOptions": {
"paths": {
"@/*": [
"../*"
]
},
"target": "ESNext",
"useDefineForClassFields": true,
"lib": [
Expand All @@ -18,14 +23,9 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"jsx": "react-jsx"
},
"include": [
"src"
],
"references": [
{
"path": "./tsconfig.node.json"
}
]
}
2 changes: 1 addition & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"engines": {
"node": "16"
},
"main": "lib/index.js",
"main": "lib/functions/src/index.js",
"dependencies": {
"@google-cloud/pubsub": "^2.19.3",
"@google-cloud/secret-manager": "^4.1.3",
Expand Down
2 changes: 1 addition & 1 deletion functions/src/notifier/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
IChangeEvent,
ICourseEvent,
ICourseSectionEvent
} from "../types";
} from "@/common/types";

const generateFooter = (event: CourseEvent) => {
return {
Expand Down
2 changes: 1 addition & 1 deletion functions/src/notifier/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 1 addition & 1 deletion functions/src/scraper/generate_events.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions functions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"compilerOptions": {
"paths": {
"@/*": [
"../*"
]
},
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
Expand Down
Loading

0 comments on commit 7de25d3

Please sign in to comment.