From 39fa62e71edf9f2215ae710b6bbe8b57f0a94953 Mon Sep 17 00:00:00 2001 From: Timofey Obraztsov Date: Thu, 7 Dec 2023 16:11:25 -0800 Subject: [PATCH] change popup to button for ap prereqs --- api/.env.local | 2 +- site/src/component/PrereqTree/PrereqTree.tsx | 135 +++++++++---------- site/src/hooks/professorData.tsx | 51 ++++--- site/src/setupProxy.js | 8 +- 4 files changed, 94 insertions(+), 102 deletions(-) diff --git a/api/.env.local b/api/.env.local index 30314109..e4d6d5e0 100644 --- a/api/.env.local +++ b/api/.env.local @@ -1 +1 @@ -PRODUCTION_DOMAIN=http://localhost:5000 \ No newline at end of file +PRODUCTION_DOMAIN=http://localhost:5001 \ No newline at end of file diff --git a/site/src/component/PrereqTree/PrereqTree.tsx b/site/src/component/PrereqTree/PrereqTree.tsx index 68df7650..8df8fc97 100644 --- a/site/src/component/PrereqTree/PrereqTree.tsx +++ b/site/src/component/PrereqTree/PrereqTree.tsx @@ -1,8 +1,8 @@ -import React, { FC } from 'react'; -import './PrereqTree.scss'; -import { Grid, Popup } from 'semantic-ui-react'; +import React, { FC } from "react"; +import "./PrereqTree.scss"; +import { Grid, Popup } from "semantic-ui-react"; -import { PrerequisiteJSONNode, PrerequisiteJSON, CourseGQLData, CourseLookup } from '../../types/types'; +import { PrerequisiteJSONNode, PrerequisiteJSON, CourseGQLData, CourseLookup } from "../../types/types"; interface NodeProps { node: string; @@ -12,18 +12,27 @@ interface NodeProps { } const Node: FC = (props) => { + console.log(props.label); return ( -
+
- {props.label} - + !props.label.startsWith("AP ") ? ( + + {props.label} + + ) : ( + + ) } - content={props.content} basic position='top center' wide='very' /> + content={props.content} + basic + position="top center" + wide="very" + />
); -} +}; interface TreeProps { prerequisiteNames: CourseLookup; @@ -34,94 +43,83 @@ interface TreeProps { const Tree: FC = (props) => { let prerequisite = props.prerequisiteJSON; - let isValueNode = typeof prerequisite === 'string'; + let isValueNode = typeof prerequisite === "string"; // if value is a string, render leaf node if (isValueNode) { - let id = (prerequisite as string).replace(/\s+/g, ''); + let id = (prerequisite as string).replace(/\s+/g, ""); let content = prerequisite; if (props.prerequisiteNames.hasOwnProperty(id)) { content = props.prerequisiteNames[id].title; } return ( -
  • - +
  • +
  • - ) + ); } // if value is an object, render the rest of the sub tree else { return ( -
    -
    - -
    - {prerequisite.hasOwnProperty('OR') ? 'one of' : 'all of'} -
    +
    +
    + +
    {prerequisite.hasOwnProperty("OR") ? "one of" : "all of"}
    -
    -
      - {(prerequisite as PrerequisiteJSON)[Object.keys(prerequisite)[0]].map( - (child, index) => ( - - ) - )} +
      +
        + {(prerequisite as PrerequisiteJSON)[Object.keys(prerequisite)[0]].map((child, index) => ( + + ))}
    - ) + ); } -} +}; -interface PrereqProps extends CourseGQLData { -} +interface PrereqProps extends CourseGQLData {} const PrereqTree: FC = (props) => { - let hasPrereqs = props.prerequisite_tree !== ''; + let hasPrereqs = props.prerequisite_tree !== ""; let hasDependencies = Object.keys(props.prerequisite_for).length !== 0; if (props.id === undefined) return <>; else if (!hasPrereqs && !hasDependencies) return ( -
    -

    - No Dependencies or Prerequisites! -

    +
    +

    No Dependencies or Prerequisites!

    ); return (
    - +
    {/* Display dependencies */} {hasDependencies && ( <> -
      -
      - {Object.values(props.prerequisite_for).map( - (dependency, index) => ( -
    • - -
    • - ) - )} +
        +
        + {Object.values(props.prerequisite_for).map((dependency, index) => ( +
      • + +
      • + ))}
      -
      - -
      - needs -
      +
      + +
      needs
      @@ -134,16 +132,12 @@ const PrereqTree: FC = (props) => {
      } */} {/* Display the class id */} - + {/* Spawns the root of the prerequisite tree */} {hasPrereqs && ( -
      - - +
      +
      )} @@ -152,14 +146,13 @@ const PrereqTree: FC = (props) => { No Prerequisites!

      } */} -
      - {props.prerequisite_text !== '' && ( + {props.prerequisite_text !== "" && (

      @@ -171,6 +164,6 @@ const PrereqTree: FC = (props) => {

      ); -} +}; -export default PrereqTree; \ No newline at end of file +export default PrereqTree; diff --git a/site/src/hooks/professorData.tsx b/site/src/hooks/professorData.tsx index 28b9ff76..92d7968d 100644 --- a/site/src/hooks/professorData.tsx +++ b/site/src/hooks/professorData.tsx @@ -1,15 +1,15 @@ -import { gql, useQuery } from '@apollo/client'; -import { ProfessorGQLData, SubCourse, CourseLookup } from '../types/types'; +import { gql, useQuery } from "@apollo/client"; +import { ProfessorGQLData, SubCourse, CourseLookup } from "../types/types"; interface ProfessorGQLResponse { - instructor: Omit & { - course_history: SubCourse[]; - } + instructor: Omit & { + course_history: SubCourse[]; + }; } // given a course id, get the gql equivalent function useProfessorGQL(professorID: string | undefined) { - const query = gql` + const query = gql` query { instructor(ucinetid:"${professorID}"){ name @@ -27,26 +27,25 @@ function useProfessorGQL(professorID: string | undefined) { } } }`; - const { loading, error, data } = useQuery(query); - if (loading || error) { - return { loading, error, professor: null }; - } - else { - if (!professorID || !data?.instructor) { - return { loading, error, professor: null }; - } - let courseHistoryLookup: CourseLookup = {}; - // maps course's id to course basic details - data!.instructor.course_history.forEach(course => { - if (course) { - courseHistoryLookup[course.id] = course; - } - }) - // create copy to override fields with lookups - let professor = { ...data!.instructor } as unknown as ProfessorGQLData; - professor.course_history = courseHistoryLookup; - return { loading, error, professor: professor }; + const { loading, error, data } = useQuery(query); + if (loading || error) { + return { loading, error, professor: null }; + } else { + if (!professorID || !data?.instructor) { + return { loading, error, professor: null }; } + let courseHistoryLookup: CourseLookup = {}; + // maps course's id to course basic details + data!.instructor.course_history.forEach((course) => { + if (course) { + courseHistoryLookup[course.id] = course; + } + }); + // create copy to override fields with lookups + let professor = { ...data!.instructor } as unknown as ProfessorGQLData; + professor.course_history = courseHistoryLookup; + return { loading, error, professor: professor }; + } } -export { useProfessorGQL } \ No newline at end of file +export { useProfessorGQL }; diff --git a/site/src/setupProxy.js b/site/src/setupProxy.js index e82dd698..aec80fa8 100644 --- a/site/src/setupProxy.js +++ b/site/src/setupProxy.js @@ -1,10 +1,10 @@ -const { createProxyMiddleware } = require('http-proxy-middleware'); +const { createProxyMiddleware } = require("http-proxy-middleware"); -module.exports = function(app) { +module.exports = function (app) { app.use( - '/api', + "/api", createProxyMiddleware({ - target: 'http://localhost:5000', + target: "http://localhost:5001", changeOrigin: true, }) );