Skip to content

Commit

Permalink
Merge pull request #657 from UTDNebula/major-names
Browse files Browse the repository at this point in the history
Standardize major names
  • Loading branch information
cubetastic33 authored Sep 12, 2023
2 parents 496ae51 + c2848ae commit 40e9371
Show file tree
Hide file tree
Showing 66 changed files with 4,212 additions and 5,552 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ EMAIL_FROM=

########## Degree validator ##########
## Required in all environments.
VALIDATOR=
NEXT_PUBLIC_VALIDATOR=


########## Node ##########
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
EMAIL_FROM: [email protected]

# DEGREE VALIDATOR
VALIDATOR: http://localhost:5000
NEXT_PUBLIC_VALIDATOR: http://localhost:5000

NODE_ENV: production
VERCEL_ENV: preview
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
EMAIL_FROM: [email protected]

# DEGREE VALIDATOR
VALIDATOR: https://localhost:5000
NEXT_PUBLIC_VALIDATOR: http://localhost:5000

NODE_ENV: test

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ yarn-error.log*
# Vercel
.vercel

# virtual environments
.venv/

.eslintcache
.firebaserc
*.cache
Expand Down
2 changes: 1 addition & 1 deletion src/components/landing/PlanCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DotsHorizontalIcon from '@/icons/DotsHorizontalIcon';
import { trpc } from '@/utils/trpc';

import PlanCardDropdown from './PlanCardDropdown';
import DeletePlanModal from '../../shared-components/DeletePlanModal';
import DeletePlanModal from '@/shared/DeletePlanModal';

export type PlanCardProps = {
id: string;
Expand Down
17 changes: 15 additions & 2 deletions src/components/onboarding/welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import React from 'react';

import AutoCompleteMajor from '@/components/AutoCompleteMajor';
import EmojiIcons from '@/icons/EmojiIcon';
import majorsList from '@data/majors.json';
import { SemesterCode } from 'prisma/utils';

import useSearch from '../search/search';
import useMajors from '@/shared/useMajors';
import Link from 'next/link';

export type WelcomeTypes = {
name: string;
Expand All @@ -27,7 +28,6 @@ export default function Welcome({
handleValidate,
semesterOptions,
}: WelcomeData): JSX.Element {
const majors = majorsList as string[];
const { name, startSemester, endSemester }: WelcomeTypes = data;

const setName = (event: SelectChangeEvent<string>) => {
Expand All @@ -43,6 +43,7 @@ export default function Welcome({
};

const [major, setMajor] = React.useState('');
const { majors, err } = useMajors();

const { results, updateQuery } = useSearch({
constraints: [0, 900], // used a random large number, since i dont know exactly how many majors there are
Expand Down Expand Up @@ -112,6 +113,18 @@ export default function Welcome({
window.scrollTo(0, 0);
}, []);

if (err) {
return (
<>
Oops, we ran into an error! Please let us know on our{' '}
<Link href="https://discord.gg/anrh9B2Z3w" className="underline">
discord
</Link>{' '}
to get it fixed as soon as possible.
</>
);
}

return (
<div>
<div className="flex flex-wrap">
Expand Down
17 changes: 15 additions & 2 deletions src/components/planner/EditableMajor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { toast } from 'react-toastify';

import EditIcon from '@/icons/EditIcon';
import { trpc } from '@/utils/trpc';
import majorsList from '@data/majors.json';
import useMajors from '@/shared/useMajors';
import Link from 'next/link';

const EditableMajor = ({
major: initialMajor,
Expand Down Expand Up @@ -63,7 +64,7 @@ const EditMajorAutocomplete = ({
setEditMajor: (a: boolean) => void;
planId: string;
}) => {
const majors = majorsList as string[];
const { majors, err } = useMajors();

const utils = trpc.useContext();

Expand All @@ -89,6 +90,18 @@ const EditMajorAutocomplete = ({
);
};

if (err) {
return (
<>
Oops, we ran into an error! Please let us know on our{' '}
<Link href="https://discord.gg/anrh9B2Z3w" className="underline">
discord
</Link>{' '}
to get it fixed as soon as possible.
</>
);
}

return (
<Autocomplete
disablePortal
Expand Down
2 changes: 1 addition & 1 deletion src/components/planner/Toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import AnalyticsWrapper from '@/components/common/AnalyticsWrapper';
import DownloadIcon from '@/icons/DownloadIcon';
import SettingsIcon from '@/icons/SettingsIcon';
import SwitchVerticalIcon from '@/icons/SwitchVerticalIcon';
import DeletePlanModal from '@/shared-components/DeletePlanModal';
import DeletePlanModal from '@/shared/DeletePlanModal';
import { trpc } from '@/utils/trpc';

import EditableMajorTitle from './EditablePlanTitle';
Expand Down
18 changes: 15 additions & 3 deletions src/components/template/CustomPlan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import AutoCompleteMajor from '@/components/AutoCompleteMajor';
import courseCode from '@/data/courseCode.json';
import { UnwrapArray } from '@/types/util-types';
import { RouterInputs, trpc } from '@/utils/trpc';
import majorsList from '@data/majors.json';
import { SemesterCode } from 'prisma/utils';

import { Page } from './Page';
Expand All @@ -15,8 +14,8 @@ import ErrorMessage from '../common/ErrorMessage';
import useSearch from '../search/search';

import type { PDFDocumentProxy } from 'pdfjs-dist';

const majors = majorsList as string[];
import useMajors from '@/shared/useMajors';
import Link from 'next/link';

type TakenCourse = UnwrapArray<RouterInputs['user']['createUserPlan']['takenCourses']>;

Expand All @@ -30,6 +29,7 @@ export default function CustomPlan({ onDismiss }: { onDismiss: () => void }) {

const [planNameError, setPlanNameError] = useState(false);
const [majorError, setMajorError] = useState(false);
const { majors, err } = useMajors();
const setErrors = () => {
setPlanNameError(name === '');
setMajorError(major === null);
Expand Down Expand Up @@ -423,6 +423,18 @@ export default function CustomPlan({ onDismiss }: { onDismiss: () => void }) {
</Page>,
];

if (err) {
return (
<>
Oops, we ran into an error! Please let us know on our{' '}
<Link href="https://discord.gg/anrh9B2Z3w" className="underline">
discord
</Link>{' '}
to get it fixed as soon as possible.
</>
);
}

return (
<>
{pages.map((p, i) => (
Expand Down
70 changes: 0 additions & 70 deletions src/data/majors.json

This file was deleted.

5 changes: 3 additions & 2 deletions src/env/schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const serverSchema = z.object({
EMAIL_SERVER_USER: z.string(),
EMAIL_SERVER_PASSWORD: z.string(),
EMAIL_FROM: z.string(),
VALIDATOR: z.string(),
});

/**
Expand All @@ -42,6 +41,7 @@ export const serverSchema = z.object({
export const clientSchema = z.object({
NEXT_PUBLIC_UMAMI_URL: z.string(),
NEXT_PUBLIC_UMAMI_WEBSITE_ID: z.string(),
NEXT_PUBLIC_VALIDATOR: z.string(),
// NEXT_PUBLIC_BAR: z.string(),
});

Expand All @@ -52,7 +52,8 @@ export const clientSchema = z.object({
* @type {{ [k in keyof z.infer<typeof clientSchema>]: z.infer<typeof clientSchema>[k] | undefined }}
*/
export const clientEnv = {
NEXT_PUBLIC_UMAMI_WEBSITE_ID: process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID,
NEXT_PUBLIC_UMAMI_URL: process.env.NEXT_PUBLIC_UMAMI_URL,
NEXT_PUBLIC_UMAMI_WEBSITE_ID: process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID,
NEXT_PUBLIC_VALIDATOR: process.env.NEXT_PUBLIC_VALIDATOR,
// NEXT_PUBLIC_BAR: process.env.NEXT_PUBLIC_BAR,
};
2 changes: 1 addition & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const theme = createTheme({
});

import { env } from '@/env/client.mjs';
import ScreenSizeWarnModal from '@/shared-components/ScreenSizeWarnModal';
import ScreenSizeWarnModal from '@/shared/ScreenSizeWarnModal';

import type { NextComponentType } from 'next'; //Import Component type

Expand Down
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions src/shared/useMajors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useEffect, useState } from 'react';

const useMajors = () => {
const [majors, setMajors] = useState<string[]>([]);
const [err, setErr] = useState<string | null>();

useEffect(() => {
fetch(`${process.env.NEXT_PUBLIC_VALIDATOR}/get-degree-plans`, {
method: 'GET',
})
.then((res) => res.json())
.then((data) => {
setMajors(
data['degree_plans'].map((degree: { display_name: string }) => degree['display_name']),
);
})
.catch((error) => {
console.error('An error occurred while trying to load majors:', error);
setErr(error.message);
});
}, []);

return { majors, err };
};

export default useMajors;
4 changes: 2 additions & 2 deletions validator/.vscode/major.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"$comment": "Generated by gen_schema.py on 2023-08-04 18:20:08.357918",
"type": "object",
"properties": {
"abbreviation": {
"id": {
"type": "string"
},
"catalog_uri": {
Expand All @@ -13,7 +13,7 @@
"minimum_credit_hours": {
"type": "number"
},
"name": {
"display_name": {
"type": "string"
},
"school": {
Expand Down
20 changes: 20 additions & 0 deletions validator/api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json
from glob import glob
from flask import Flask, Response, request, make_response
from flask_cors import CORS

Expand All @@ -11,6 +13,15 @@ def __init__(self, message: str, http_response_code: int = 400) -> None:
super().__init__(self.message)


# Load the list of degree plans that we support along with their json data
plans = []
for fname in glob("./degree_data/*.json"):
with open(fname, "r") as f:
data = json.load(f)
plans.append({"display_name": data["display_name"], "id": data["id"]})


# Instantiate flask app and ratelimiter
app = Flask(__name__)
CORS(app)

Expand All @@ -25,6 +36,15 @@ def root_() -> Response:
)


@app.route("/get-degree-plans", methods=["GET"])
def get_degree_plans() -> Response:
# Returns a list of degree plans that validator supports. This is just a list of the display names of all the JSON
# plans we have.
return make_response(
{"message": f"Supported degree plans.", "degree_plans": plans}, 200
)


@app.route("/test-validate", methods=["POST"])
def test_validate() -> Response:
try:
Expand Down
Loading

0 comments on commit 40e9371

Please sign in to comment.