Skip to content

Commit

Permalink
Update all functions to const arrow functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquelinecai committed Dec 8, 2024
1 parent 8a693c9 commit 8acc610
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 39 deletions.
66 changes: 36 additions & 30 deletions client/src/modules/Admin/Components/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const Admin = () => {
| 'subjects'
| 'database'
| 'description'
| 'similarity'
| 'summarize'
| 'failure';
const [updated, setUpdated] = useState<updatedStates>('empty');
Expand All @@ -42,6 +43,7 @@ export const Admin = () => {
subjects: 'Subject full name data successfully updated',
database: 'Database successfully initialized',
description: 'Course description data successfully added',
similarity: 'Similarity data successfully added',
summarize: 'All courses successfully summarized',
failure: 'API failed'
};
Expand All @@ -59,7 +61,7 @@ export const Admin = () => {
* Confirms if the logged-in user is an admin
*/
useEffect(() => {
async function confirmAdmin() {
const confirmAdmin = async () => {
const response = await axios.post(`/api/admin/token/validate`, {
token: token
});
Expand All @@ -79,7 +81,7 @@ export const Admin = () => {
* pending (awaiting approval), and reported (hidden and awaiting approval)
*/
useEffect(() => {
async function loadReviews() {
const loadReviews = async () => {
const pending = await axios.post('/api/admin/reviews/get-pending', {
token: token
});
Expand All @@ -100,7 +102,7 @@ export const Admin = () => {
* Helper function to remove a review from a list of reviews and
* return the updated list
*/
function removeReviewFromList(reviewToRemove: Review, reviews: Review[]) {
const removeReviewFromList = (reviewToRemove: Review, reviews: Review[]) => {
reviews = reviews.filter((review: Review) => {
return review && review._id !== reviewToRemove._id;
});
Expand All @@ -111,7 +113,7 @@ export const Admin = () => {
* Call when user asks to approve a review. Accesses the Reviews database
* and changes the review with this id to visible.
*/
async function approveReview(review: Review) {
const approveReview = async (review: Review) => {
const response = await axios.post('/api/admin/reviews/approve', {
review: review,
token: token
Expand All @@ -130,7 +132,7 @@ export const Admin = () => {
* Call when user asks to remove a review. Accesses the Reviews database
* and deletes the review with this id.
*/
async function removeReview(review: Review, isUnapproved: boolean) {
const removeReview = async (review: Review, isUnapproved: boolean) => {
try {
const response = await axios.post('/api/admin/reviews/remove', {
review: review,
Expand Down Expand Up @@ -159,7 +161,7 @@ export const Admin = () => {
/**
* Call when admin would like to mass-approve all of the currently pending reviews.
*/
async function approveAllReviews(reviews: Review[]) {
const approveAllReviews = async () => {
const response = await axios.post('/api/admin/reviews/approve/all', {
token: token
});
Expand All @@ -170,10 +172,12 @@ export const Admin = () => {
}
}

// Call when user selects "Sumarize Reviews" button. Calls endpoint to generate
// summaries and tags using AI for all courses with a freshness above a certain
// threshold, then updates those courses to include these new summaries and tags.
async function summarizeReviews() {
/**
* Call when user selects "Sumarize Reviews" button. Calls endpoint to generate
* summaries and tags using AI for all courses with a freshness above a certain
* threshold, then updates those courses to include these new summaries and tags.
*/
const summarizeReviews = async () => {
console.log('Updating all courses with AI');
setUpdating(true);
setUpdatingField('summarizing');
Expand All @@ -191,7 +195,7 @@ export const Admin = () => {
* Call when user asks to un-report a reported review. Accesses the Reviews database
* and changes the reported flag for this review to false.
*/
async function unReportReview(review: Review) {
const unReportReview = async (review: Review) => {
const response = await axios.post('/api/admin/reviews/restore', {
review: review,
token: token
Expand All @@ -211,7 +215,7 @@ export const Admin = () => {
* course API for new classes and updates classes existing in the database.
* Should run once a semester, when new classes are added to the roster.
*/
async function addNewSemesters(semesters: string[]) {
const addNewSemesters = async (semesters: string[]) => {
console.log('Adding new semester...');
setUpdating(true);
setUpdatingField('new semesters');
Expand All @@ -233,14 +237,16 @@ export const Admin = () => {
setUpdated('semester');
}

// Call when user selects "Initialize Database" button. Scrapes the Cornell
// Course API to store all classes and subjects in the local database.
// Then, runs code to store id's of cross-listed classes against each class.
// Should only be run ONCE when the app is initialzied.
//
// NOTE: requires an initialize flag to ensure the function is only run on
// a button click without this, it will run every time this component is created.
async function addAllCourses() {
/**
* Call when user selects "Initialize Database" button. Scrapes the Cornell
* Course API to store all classes and subjects in the local database.
* Then, runs code to store id's of cross-listed classes against each class.
* Should only be run ONCE when the app is initialzied.
*
* NOTE: requires an initialize flag to ensure the function is only run on
* a button click without this, it will run every time this component is created.
*/
const addAllCourses = async () => {
console.log('Initializing database');
setUpdating(true);
setUpdatingField('all database');
Expand All @@ -260,7 +266,7 @@ export const Admin = () => {
* Call when admin wants to update professors for users to search through
* when clicking the "Update Professors" button
*/
async function updateProfessors() {
const updateProfessors = async () => {
console.log('Updating professors');
setUpdating(true);
setUpdatingField('professors');
Expand All @@ -281,7 +287,7 @@ export const Admin = () => {
* Call when admin wants to reset all professors in classes when clicking the
* "Reset Professors" button
*/
async function resetProfessors() {
const resetProfessors = async () => {
console.log('Setting the professors to an empty array');
setUpdating(true);
setUpdatingField('professors to empty arrays');
Expand All @@ -302,7 +308,7 @@ export const Admin = () => {
* Call when user selects "Update Descriptions" button. Scrapes the Course API
* to retrieve course description and stores them in the Course database.
*/
async function updateDescriptions() {
const updateDescriptions = async () => {
console.log('Updating course descriptions');
setUpdating(true);
setUpdatingField('course descriptions');
Expand All @@ -322,7 +328,7 @@ export const Admin = () => {
* Call when admin wants to update the list of subjects users can search through
* when clicking the "Update Subjects" button
*/
async function updateSubjects() {
const updateSubjects = async () => {
setUpdating(true);
setUpdatingField('subjects');
const response = await axios.post('/api/admin/subjects/update', {
Expand All @@ -341,7 +347,7 @@ export const Admin = () => {
* Call when admin wants to update the similar courses data when clicking the
* "Update Similarity Data" button
*/
async function updateSimilarityData() {
const updateSimilarityData = async () => {
console.log('Updatng course similarity data')
setUpdating(true)
setUpdatingField("course similarity data")
Expand All @@ -359,7 +365,7 @@ export const Admin = () => {
* Handle the first click to the "Initialize Database" button. Show an alert
* and update state to remember the next click will be a double click.
*/
function firstClickHandler() {
const firstClickHandler = () => {
alert(
'<div><h1>Warning!</h1><p>Clicking again will reset all data in the database. Are you sure you want to do this?</p></div>'
);
Expand All @@ -372,7 +378,7 @@ export const Admin = () => {
* If this is the user's second click, call addAllCourses above to initiaize
* the local database
*/
function renderInitButton() {
const renderInitButton = () => {
// Offer button to edit database
if (doubleClick) {
return (
Expand Down Expand Up @@ -403,7 +409,7 @@ export const Admin = () => {
}
}

function renderAdmin(userToken: string) {
const renderAdmin = (userToken: string) => {
return (
<div className={styles.adminWrapper}>
<div className="headInfo">
Expand Down Expand Up @@ -497,7 +503,7 @@ export const Admin = () => {
<button
type="button"
className={styles.massApproveButton}
onClick={() => approveAllReviews(pendingReviews)}
onClick={() => approveAllReviews()}
>
Approve all pending reviews
</button>
Expand Down Expand Up @@ -535,7 +541,7 @@ export const Admin = () => {
);
}

function adminLogin() {
const adminLogin = () => {
if (loading) {
return <Loading />;
} else if (isLoggedIn && token && isAdmin) {
Expand Down
4 changes: 2 additions & 2 deletions client/src/modules/Admin/Components/AdminReview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const UpdateReview = ({
const [shortName, setShortName] = useState<string>('');
const [fullName, setFullName] = useState<string>('');

async function getCourse() {
const getCourse = async () => {
const response = await axios.post(`/api/courses/get-by-id`, {
courseId: review.class
});
Expand All @@ -41,7 +41,7 @@ const UpdateReview = ({

getCourse();

function renderButtons(adminReview: any) {
const renderButtons = (adminReview: any) => {
const reported = adminReview.reported;
if (reported === 1) {
return (
Expand Down
10 changes: 5 additions & 5 deletions client/src/modules/Admin/Components/ManageAdminModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ const ManageAdminModal = ({ token, open, setOpen }: Props) => {
const [admins, setAdmins] = useState<Student[]>([]);
const [netId, setNetId] = useState<string>('');

function closeModal() {
const closeModal = () => {
setOpen(false);
}

/**
* Endpoint to get all admins
*/
useEffect(() => {
async function getAdmins() {
const getAdmins = async () => {
const response = await axios.post('/api/admin/users/get', {
token: token
});
Expand All @@ -40,7 +40,7 @@ const ManageAdminModal = ({ token, open, setOpen }: Props) => {
* Removes an admin from the list, giving that user 'regular' privilege
* @param user assumes that this user already has admin privilege
*/
async function removeAdmin(user: Student) {
const removeAdmin = async (user: Student) => {
const response = await axios.post('/api/admin/users/remove', {
userId: user.netId,
token: token
Expand All @@ -58,7 +58,7 @@ const ManageAdminModal = ({ token, open, setOpen }: Props) => {
* Calls endpoint to add or update a user with admin privilege
* @param _netId the user's net id
*/
async function addAdminByNetId(_netId: string) {
const addAdminByNetId = async (_netId: string) => {
const response = await axios.post('/api/admin/users/add', {
userId: _netId,
token: token
Expand All @@ -69,7 +69,7 @@ const ManageAdminModal = ({ token, open, setOpen }: Props) => {
}
}

function onTextChange(newText: string) {
const onTextChange = (newText: string) => {
setNetId(newText);
}

Expand Down
4 changes: 2 additions & 2 deletions client/src/modules/Admin/Components/Stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Stats = ({ token }: StatsProps) => {
Fires on every render to check for approvals or removals of reviews
*/
useEffect(() => {
async function getCounts() {
const getCounts = async () => {
const response = await axios.post('/api/admin/reviews/count', {
token: token
});
Expand All @@ -34,7 +34,7 @@ const Stats = ({ token }: StatsProps) => {
Function to download a file containing all reviewed classes in the database and their
number of reviews
*/
async function downloadCSVFile() {
const downloadCSVFile = async () => {
const element = document.createElement('a');
let csv = '';

Expand Down

0 comments on commit 8acc610

Please sign in to comment.