Skip to content

Commit

Permalink
Merge branch 'main' into jac/rec-frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquelinecai committed Nov 22, 2024
2 parents c602b94 + b94324a commit b107c54
Show file tree
Hide file tree
Showing 14 changed files with 775 additions and 142 deletions.
95 changes: 61 additions & 34 deletions client/src/modules/Admin/Components/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,28 @@ export const Admin = () => {

const [updating, setUpdating] = useState<boolean>(false);
type updatedStates =
| 'empty'
| 'semester'
| 'profsReset'
| 'profsUpdate'
| 'subjects'
| 'database'
| 'description';
'empty' |
'semester' |
'profsReset' |
'professors' |
'subjects' |
'database' |
'description' |
'similarity';
const [updated, setUpdated] = useState<updatedStates>('empty');
const successMessages = {
empty: '',
semester: 'New semester data successfully added',
profsReset: 'Professor data successfully reset to empty',
profsUpdate: 'Professor data successfully updated',
subjects: 'Subject full name data successfully updated',
database: 'Database successfully initialized',
description: 'Course description data successfully added'
'empty': '',
'semester': "New semester data successfully added",
'profsReset': "Professor data successfully reset to empty",
'professors': "Professor data successfully updated",
'subjects': "Subject full name data successfully updated",
'database': "Database successfully initialized",
'description': "Course description data successfully added",
'similarity': "Similarity data successfully added",
};
const [updatingField, setUpdatingField] = useState<string>('');

const [addSemester] = useState('');
const [addSemester] = useState(['FA24', 'SP25']);
const [isAdminModalOpen, setIsAdminModalOpen] = useState<boolean>(false);

const { isLoggedIn, token, isAuthenticating } =
Expand Down Expand Up @@ -187,23 +189,26 @@ 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 addNewSem(semester: string) {
async function addNewSemesters(semesters: string[]) {
console.log('Adding new semester...');
setUpdating(true);
setUpdatingField('new semester');
setUpdatingField('new semesters');
//wz
const response = await axios.post('/api/admin/semester/add', {
semester,
token: token
});
const result = response.data.result;
if (result === true) {
console.log('New Semester Added');
setUpdating(false);
setUpdated('semester');
} else {
console.log('Unable to add new semester!');
for (const semester of semesters) {
const response = await axios.post('/api/admin/semester/add', {

Check warning on line 198 in client/src/modules/Admin/Components/Admin.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected `await` inside a loop

Check warning on line 198 in client/src/modules/Admin/Components/Admin.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected `await` inside a loop
semester,
token: token
});
const result = response.data.result;
if (!result) {
console.error(`Unable to add new semester ${semester}!`);
continue;
} else {
console.log(`New Semester ${semester} Added`);
}
}
setUpdating(false);
setUpdated('semester');
}

// Call when user selects "Initialize Database" button. Scrapes the Cornell
Expand Down Expand Up @@ -244,7 +249,7 @@ export const Admin = () => {
if (response.status === 200) {
console.log('Updated the professors');
setUpdating(false);
setUpdated('profsUpdate');
setUpdated('professors');
} else {
console.log('Error at setProfessors');
}
Expand Down Expand Up @@ -310,6 +315,20 @@ export const Admin = () => {
}
}

async function updateSimilarityData() {
console.log('Updatng course similarity data')
setUpdating(true)
setUpdatingField("course similarity data")
const response = await axios.post('/api/admin/rec/similarity', { token: token });
if (response.status === 200) {
console.log('Updated course similarity data')
setUpdating(false)
setUpdated('similarity')
} else {
console.log('Error at updateSimilarityData')
}
}

/**
* 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.
Expand Down Expand Up @@ -377,7 +396,7 @@ export const Admin = () => {
disabled={updating}
type="button"
className={styles.adminButtons}
onClick={() => addNewSem(addSemester)}
onClick={() => addNewSemesters(addSemester)}
>
Add New Semester
</button>
Expand Down Expand Up @@ -413,9 +432,17 @@ export const Admin = () => {
>
Update Subjects
</button>
<button
disabled={updating}
type="button"
className={styles.adminButtons}
onClick={() => updateSimilarityData()}
>
Update Similarity Data
</button>
{renderInitButton()}
</div>
</div>
</div >
</div >

<ManageAdminModal
open={isAdminModalOpen}
Expand All @@ -429,7 +456,7 @@ export const Admin = () => {
<p>Updating {updatingField} in the Course database.</p>
<p>This process can take up to 15 minutes.</p>
</div>
</div>
</div >

<div className="StagedReviews">
<h1>Pending Reviews</h1>
Expand Down Expand Up @@ -470,7 +497,7 @@ export const Admin = () => {
})}
</div>
</div>
</div>
</div >
);
}

Expand Down
125 changes: 62 additions & 63 deletions client/src/modules/Course/Components/Course.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const Course = () => {
let valB = 'Not Listed';

if (a.professors) {
const profsA = a.professors.filter((prof : String) =>
const profsA = a.professors.filter((prof: String) =>
prof && prof !== 'Not Listed');
valA = profsA.length > 0
? profsA.sort()[0]
Expand All @@ -73,7 +73,7 @@ export const Course = () => {
return 1;
}
if (b.professors) {
const profsB = b.professors.filter((prof : String) =>
const profsB = b.professors.filter((prof: String) =>
prof && prof !== 'Not Listed');
valB = profsB.length > 0
? profsB.sort()[0]
Expand All @@ -87,7 +87,7 @@ export const Course = () => {
} else if (valB === 'Not Listed') {
return -1;
}

if (valA < valB) {
return -1;
} else if (valB < valA) {
Expand Down Expand Up @@ -218,75 +218,74 @@ export const Course = () => {
{/* Course Name, Button + Gauges */}
<div className={styles.leftPanel}>
<div className={styles.classinfo}>
<h1
data-cy={`course-title-${selectedClass.classSub.toLowerCase()}-${
selectedClass.classNum
<h1
data-cy={`course-title-${selectedClass.classSub.toLowerCase()}-${selectedClass.classNum
}`}
>
{selectedClass.classTitle}
</h1>
<div className={styles.subtitle}>
{selectedClass.classSub.toUpperCase() +
' ' +
selectedClass.classNum +
', ' +
lastOfferedSems(selectedClass)}
</div>
<button
data-cy="leave-review-button"
className={styles.reviewbutton}
onClick={() => setOpen(true)}
>
Leave a review
</button>
>
{selectedClass.classTitle}
</h1>
<div className={styles.subtitle}>
{selectedClass.classSub.toUpperCase() +
' ' +
selectedClass.classNum +
', ' +
lastOfferedSems(selectedClass)}
</div>
<button
data-cy="leave-review-button"
className={styles.reviewbutton}
onClick={() => setOpen(true)}
>
Leave a review
</button>
</div>

<div className={styles.gauges}>
<Gauge
rating={selectedClass.classRating}
label="Overall"
isOverall={true}
/>
<Gauge
rating={selectedClass.classDifficulty}
label="Difficulty"
isOverall={false}
/>
<Gauge
rating={selectedClass.classWorkload}
label="Workload"
isOverall={false}
/>
</div>
<div className={styles.gauges}>
<Gauge
rating={selectedClass.classRating}
label="Overall"
isOverall={true}
/>
<Gauge
rating={selectedClass.classDifficulty}
label="Difficulty"
isOverall={false}
/>
<Gauge
rating={selectedClass.classWorkload}
label="Workload"
isOverall={false}
/>
</div>
</div>
<div className={styles.rightPanel}>
{/* Reviews Displaying */}
<div className={styles.reviewscontainer}>
<div className={styles.bar}>
<h2>Past Reviews ({courseReviews?.length}) </h2>
<div>
<label htmlFor="sort-reviews">Sort by: </label>
<select
name="sort-reviews"
id="sort-reviews"
onChange={sortReviewsBy}
className={styles.filtertext}
>
<option value="helpful">Most Helpful</option>
<option value="recent">Recent</option>
<option value="professor">Professor</option>
</select>
</div>
</div>
<div className={styles.reviews}>
<CourseReviews
reviews={courseReviews}
isPreview={false}
isProfile={false}
token={token}
/>
<div className={styles.bar}>
<h2>Past Reviews ({courseReviews?.length}) </h2>
<div>
<label htmlFor="sort-reviews">Sort by: </label>
<select
name="sort-reviews"
id="sort-reviews"
onChange={sortReviewsBy}
className={styles.filtertext}
>
<option value="helpful">Most Helpful</option>
<option value="recent">Recent</option>
<option value="professor">Professor</option>
</select>
</div>
</div>
<div className={styles.reviews}>
<CourseReviews
reviews={courseReviews}
isPreview={false}
isProfile={false}
token={token}
/>
</div>
</div>
</div>`
</div>

Expand Down
10 changes: 10 additions & 0 deletions common/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface Class {
classRating?: number;
classWorkload?: number;
classDifficulty?: number; // the average difficulty rating from reviews
recommendations: Recommendation[];
}

export interface Student {
Expand Down Expand Up @@ -59,3 +60,12 @@ export interface Professor {
readonly courses: string[];
readonly major: string;
}

interface Recommendation {
readonly _id: string;
className: string;
classSub: string;
classNum: number;
tags: string[];
similarityScore: number;
}
Loading

0 comments on commit b107c54

Please sign in to comment.