Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to vite #375

Merged
merged 31 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0bd5327
Migrate to vite. Update packages (react, react-router-dom, etc.). Rem…
js0mmer Oct 31, 2023
1c5cfbd
Run eslint fix, manually fix remaining eslint errors. Fixes for updat…
js0mmer Nov 1, 2023
e4dc75b
Update build path for site
js0mmer Nov 1, 2023
fabac38
Update readme and add start script
js0mmer Nov 1, 2023
bb158f9
Uninstall unused react-transition-group. Add @nivo/core to package.json
js0mmer Nov 1, 2023
7899c04
Merge branch 'master' into vite
js0mmer Nov 7, 2023
4309753
Fix dnd
js0mmer Nov 7, 2023
ffe94e5
Update packages
js0mmer Nov 7, 2023
baddb27
Fix review form
js0mmer Nov 9, 2023
943e60a
Update package.json. Specify node>=18
js0mmer Nov 11, 2023
a9afc58
Update README node versions
js0mmer Nov 11, 2023
8b78b21
Update react-cookie and react-google-recaptcha
js0mmer Nov 11, 2023
9a94829
Update axios
js0mmer Nov 11, 2023
b008d68
Update package-lock node engine
js0mmer Nov 11, 2023
22baaeb
Rename main back to index. Fix indentation in vite config
js0mmer Dec 8, 2023
69132f3
Fix build script
js0mmer Dec 8, 2023
a95e3a1
Add eslint react plugin
js0mmer Dec 9, 2023
04fee22
Merge branch 'master' into vite
js0mmer Dec 15, 2023
dcd8ee9
Update vite proxy port to 8080
js0mmer Dec 15, 2023
e861a73
Merge branch 'master' into vite
js0mmer Dec 17, 2023
393f2dc
Merge branch 'master' into vite
js0mmer Dec 19, 2023
41f1353
Specify node 18/20. Update readme
js0mmer Dec 19, 2023
d25e289
No console warn rule
js0mmer Dec 21, 2023
2953e5b
Update some packages
js0mmer Dec 21, 2023
b0c36ac
Update nivo and vite 5
js0mmer Dec 21, 2023
4d1c762
Fix package engines
js0mmer Dec 21, 2023
4e822b1
Update react-redux to v9 and rtk to v2
js0mmer Dec 21, 2023
cd28a8a
Clean up index.html. Add semantic ui css as dependency instead of usi…
js0mmer Dec 23, 2023
61ae33b
Merge remote-tracking branch 'origin/master' into vite
js0mmer Jan 21, 2024
257ff74
Fix faulty merging for review form. Fix verified reviews checkbox
js0mmer Jan 21, 2024
75ece58
Remove apollo client
js0mmer Jan 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 28 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Features include:
* MongoDB
* GraphQL
* TypeScript
* Vite

## First time setup
### Committee Members
Expand All @@ -37,18 +38,19 @@ Features include:
git clone https://github.com/icssc/peterportal-client
```

2. Switch to a branch you will be working on.
```
git checkout -b [branch name]
```
2. Check your Node version with `node -v`. Make sure you have version 18 or 20 LTS. If you don't, we recommend [nvm](https://github.com/nvm-sh/nvm) to manage node versions (or [nvm-windows](https://github.com/coreybutler/nvm-windows)).

3. Check your Node version with `node -v`. Make sure you have version 14 or above (18 recommended).
3. `cd` into the cloned repo.

4. Open a terminal window and `cd` into the directory of your repo.
4. Run `npm install` to install all node dependencies for the site and API. This may take a few minutes.

5. Run `npm install` to install all node dependencies for the site and API. This may take a few minutes.
5. Setup the appropriate environment variables provided by the project lead.

6. Switch to a branch you will be working on for your current task (pick a name that's relevant to the issue).
```
git checkout -b [branch name]
```

6. Setup the appropriate environment variables provided by the project lead.
### Open Source Contributors
1. Fork the project by clicking the fork button in the top right, above the about section.

Expand All @@ -57,26 +59,21 @@ Features include:
git clone https://github.com/<your username>/peterportal-client
```

3. Switch to a branch you will be working on.
```
git checkout -b [branch name]
```

4. Check your Node version with `node -v`. Make sure you have version 14 or above (18 recommended).
3. Check your Node version with `node -v`. Make sure you have version 18 or 20 LTS. If you don't, we recommend [nvm](https://github.com/nvm-sh/nvm) to manage node versions (or [nvm-windows](https://github.com/coreybutler/nvm-windows)).

5. Open a terminal window and `cd` into the directory of your repo.
4. `cd` into the cloned repo.

6. Run `npm install` to install all node dependencies for the site and API. This may take a few minutes.
5. Run `npm install` to install all node dependencies for the site and API. This may take a few minutes.

7. Create a .env file in the api directory with the following contents:
6. Create a .env file in the api directory with the following contents:
```
PUBLIC_API_URL=https://api.peterportal.org/rest/v0/
PUBLIC_API_GRAPHQL_URL=https://api.peterportal.org/graphql/
PORT=8080
```
Note: the port should also match the one set up on the frontend's proxy to the backend under `site/src/setupProxy.js` By default this is 8080.
Note: the port should also match the one set up on the frontend's proxy to the backend under `site/vite.config.ts` By default this is 8080.

8. (Optional) Set up your own MongoDB and Google OAuth to be able to test features that require signing in such as leaving reviews or saving roadmaps to your account. Add additional variables/secrets to the .env file from the previous step.
7. (Optional) Set up your own MongoDB and Google OAuth to be able to test features that require signing in such as leaving reviews or saving roadmaps to your account. Add additional variables/secrets to the .env file from the previous step.
```
MONGO_URL=<secret>
SESSION_SECRET=<secret>
Expand All @@ -86,10 +83,20 @@ GRECAPTCHA_SECRET=<secret>
ADMIN_EMAILS=["<your email>"]
```

## Open Source Contribution Guide
1. Choose an issue you would like to work on under the issues tab. Leave a comment letting us know you'll work on this issue.

2. We recommend you switch to a branch you will be working on for each feature.
```
git checkout -b [branch name]
```

3. Once your feature is ready, [open a pull request](https://github.com/icssc/peterportal-client/compare) and a member from our team will review it. Follow the pull request template.

## Running the project locally (after setup)
1. Open two terminal windows and `cd` into the directory of your repo in each of them.

2. In the first terminal window, enter the client directory with `cd site`. Then run the React development server using `npm start`. Ensure the server is running on port 3000 by default.
2. In the first terminal window, enter the client directory with `cd site`. Then run the Vite development server using `npm run dev`. Ensure the server is running on port 3000 by default.

3. In the second terminal window, enter the API directory with `cd api`. Then run the Express development server using `npm run dev`. Ensure the server is running on port 8080 by default.

Expand All @@ -101,8 +108,7 @@ ADMIN_EMAILS=["<your email>"]
We consolidate our data directly from official UCI sources such as: UCI Catalogue, UCI Public Records Office, and UCI WebReg (courtesy of [PeterPortal API](https://github.com/icssc/peterportal-api-next)).

## Bug Report
🐞 If you encountered any issues or bug, please open an issue @ https://github.com/icssc-projects/peterportal-client/issues/new

🐞 If you encountered any issues or bug, please open an issue @ https://github.com/icssc/peterportal-client/issues/new

## Other Disclaimer
✅ Although we consolidate our data directly from official UCI sources, this application is by all means, not an official UCI tool. We stride to keep our data as accurate as possible with the limited support we have from UCI. Please take that into consideration while using this Website.
Expand Down
59 changes: 32 additions & 27 deletions api/src/controllers/courses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,68 @@ import express, { Request } from 'express';
import fetch from 'node-fetch';
import { GenericObject } from '../types/types';
import courseDummy from '../dummy/course.json';
import {getCourseQuery} from '../helpers/gql';
import { getCourseQuery } from '../helpers/gql';
var router = express.Router();

/**
* PPAPI proxy for course data
* PPAPI proxy for course data
*/
router.get('/api', (req: Request<{}, {}, {}, { courseID: string }>, res) => {
let r = fetch(process.env.PUBLIC_API_URL + 'courses/' + encodeURIComponent(req.query.courseID), {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
Accept: 'application/json',
},
});
console.log(req.query.courseID)
console.log(req.query.courseID);

r.then((response) => response.json())
.then((data) => res.send(data.payload))
r.then((response) => response.json()).then((data) => res.send(data.payload));
});

/**
* PPAPI proxy for course data
* PPAPI proxy for course data
*/
router.post('/api/batch', (req: Request<{}, {}, { courses: string[] }>, res) => {
if (req.body.courses.length == 0) {
res.json({});
}
else {
} else {
let r = fetch(process.env.PUBLIC_API_GRAPHQL_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: getCourseQuery(req.body.courses)
})
query: getCourseQuery(req.body.courses),
}),
});

r.then((response) => response.json())
.then((data) => res.json(
Object.fromEntries(
Object.entries(data.data).filter(([_, x]) => x !== null).map(([_, x]) => [(x as { id: string }).id, x])
)
))
r.then((response) => response.json()).then((data) =>
res.json(
Object.fromEntries(
Object.entries(data.data)
.filter(([_, x]) => x !== null)
.map(([_, x]) => [(x as { id: string }).id, x]),
),
),
);
}
});

/**
* PPAPI proxy for grade distribution
*/
router.get('/api/grades',
(req: Request<{}, {}, {}, { department: string; number: string; }>, res) => {
let r = fetch(process.env.PUBLIC_API_URL + 'grades/raw?department=' + encodeURIComponent(req.query.department) + '&courseNumber=' + req.query.number);
router.get('/api/grades', (req: Request<{}, {}, {}, { department: string; number: string }>, res) => {
let r = fetch(
process.env.PUBLIC_API_URL +
'grades/raw?department=' +
encodeURIComponent(req.query.department) +
'&courseNumber=' +
req.query.number,
);

r.then((response) => response.json())
.then((data) => {
res.send(data.payload)
})
r.then((response) => response.json()).then((data) => {
res.send(data.payload);
});
});

export default router;
export default router;
23 changes: 10 additions & 13 deletions api/src/controllers/professors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,32 @@ import { getProfessorQuery } from '../helpers/gql';
var router = express.Router();

/**
* PPAPI proxy for professor data
* PPAPI proxy for professor data
*/
router.get('/api', function (req: Request<{}, {}, {}, { ucinetid: string }>, res) {
let r = fetch(process.env.PUBLIC_API_URL + 'instructors/' + req.query.ucinetid);

r.then((response) => response.json())
.then((data) => res.send(data))
r.then((response) => response.json()).then((data) => res.send(data));
});

/**
* PPAPI proxy for professor data
* PPAPI proxy for professor data
*/
router.post('/api/batch', (req: Request<{}, {}, { professors: string[] }>, res) => {
if (req.body.professors.length == 0) {
res.json({});
}
else {
} else {
let r = fetch(process.env.PUBLIC_API_GRAPHQL_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: getProfessorQuery(req.body.professors)
})
query: getProfessorQuery(req.body.professors),
}),
});

r.then((response) => response.json())
.then((data) => res.json(data.data))
r.then((response) => response.json()).then((data) => res.json(data.data));
}
});

Expand All @@ -54,7 +51,7 @@ router.get('/api/grades/:name', function (req, res, next) {
r.then((response) => {
status = response.status;
return response.json();
}).then((data) => res.status(status).send(data.payload))
}).then((data) => res.status(status).send(data.payload));
});

export default router;
export default router;
Loading