Skip to content

Commit

Permalink
Update getCourseInfo and getCoursesList queries to use graphql (#907)
Browse files Browse the repository at this point in the history
* added apollo client + some helper funcs

* added some helper funcs

* attempt at converting timetable.ts to use graphql to handle term details

* updated getCoursesList with gql for initial review

* improvement: integrated gql for getCoursesList

* updated getCourseInfo to use graphql query (#906)

* feat: make graphql query to get course info

* format graphql output to match rest api output

* use graphql data instead of rest api data

* removed unnecessary fields from qraphql query

* clean up code

* clean up code

* clean up code

* clean up code

* clean up code

* removed references to old timetable scraper

* removed unused logic from timetable.ts + removed 'lastUpdated' status from footer

---------

Co-authored-by: ray <[email protected]>
Co-authored-by: Shaam <[email protected]>
Co-authored-by: jordansbenjamin <[email protected]>
  • Loading branch information
4 people authored Oct 22, 2024
1 parent 19eb91a commit b33109f
Show file tree
Hide file tree
Showing 19 changed files with 428 additions and 123 deletions.
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"style": "prettier --write 'src/**/*.{ts,tsx}' && eslint --fix 'src/**/*.{ts,tsx}'"
},
"dependencies": {
"@apollo/client": "3.11.8",
"@date-io/date-fns": "3.0.0",
"@emotion/react": "11.13.0",
"@emotion/styled": "11.13.0",
Expand Down
172 changes: 161 additions & 11 deletions client/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ const App: React.FC = () => {
setTermsData,
setTermNumber,
setCoursesList,
setLastUpdated,
selectedTimetable,
displayTimetables,
setDisplayTimetables,
Expand Down Expand Up @@ -204,9 +203,8 @@ const App: React.FC = () => {
* Retrieves the list of all courses from the scraper backend
*/
const fetchCoursesList = async () => {
const { courses, lastUpdated } = await getCoursesList(year, term);
const { courses } = await getCoursesList(term);
setCoursesList(courses);
setLastUpdated(lastUpdated);
};

if (year !== invalidYearFormat) fetchReliably(fetchCoursesList);
Expand Down Expand Up @@ -294,7 +292,7 @@ const App: React.FC = () => {
const codes: string[] = Array.isArray(data) ? data : [data];
Promise.all(
codes.map((code) =>
getCourseInfo(year, term, code, isConvertToLocalTimezone).catch((err) => {
getCourseInfo(term, code, isConvertToLocalTimezone).catch((err) => {
return err;
}),
),
Expand Down
12 changes: 8 additions & 4 deletions client/src/api/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ApolloClient, InMemoryCache } from '@apollo/client';

export enum Env {
DEV = 'development',
TEST = 'test',
Expand All @@ -10,14 +12,16 @@ interface Config {
auto: string;
server: string;
}

const HASURAGRES_GRAPHQL_API = 'https://graphql.csesoc.app/v1/graphql';
const LOCAL = 'http://localhost:3001';
const LIVE = 'https://timetable.devsoc.app';

export const client = new ApolloClient({
uri: HASURAGRES_GRAPHQL_API,
cache: new InMemoryCache(),
});

const API_CONFIG: Record<string, Config> = Object.freeze({
[Env.DEV]: { timetable: `${LOCAL}/api`, auto: `${LOCAL}/api/auto`, server: `${LOCAL}/api` },
[Env.TEST]: { timetable: `${LOCAL}/api`, auto: `${LOCAL}/api/auto`, server: `${LOCAL}/api` },
[Env.MOCK]: { timetable: `${LIVE}/api`, auto: `${LOCAL}/api/auto`, server: `${LOCAL}/api` },
[Env.PROD]: { timetable: `${LIVE}/api`, auto: `/api/auto`, server: `/api` },
});
export const API_URL: Config = API_CONFIG[import.meta.env.VITE_APP_ENVIRONMENT || Env.DEV];
Loading

0 comments on commit b33109f

Please sign in to comment.