Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3bd6d94
fixed summation after long fight with git :!
LSKpr May 6, 2025
c6a79a2
sorting kinda works - some problems exist
LSKpr May 7, 2025
6ef0ac0
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course
LSKpr May 7, 2025
1d02b82
fixed search + filter interaction
LSKpr May 7, 2025
9e6da22
sorting is better now / Metallic Materials are the only issue
LSKpr May 7, 2025
ed3e93f
asc/desc have correct icon now
LSKpr May 7, 2025
b4a43a4
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 7, 2025
1973a40
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 7, 2025
1880408
added favicon
LSKpr May 8, 2025
2e799ef
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 8, 2025
43a430f
fixed the website name in index.html
LSKpr May 8, 2025
9e57a66
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 8, 2025
1e2ac77
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 8, 2025
7fafcfb
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 8, 2025
45b7ae2
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 8, 2025
a6fce52
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 8, 2025
e7f0385
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 8, 2025
811154c
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 8, 2025
8662574
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 8, 2025
fd86c41
ArrowLeft closes the CoursePopup
LSKpr May 8, 2025
c461366
popup variables moved to the model
LSKpr May 8, 2025
f5a14d6
popup variables moved to the model
LSKpr May 8, 2025
8358f73
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 8, 2025
d80e280
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 8, 2025
df37e10
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 9, 2025
d18cc83
bug fix
LSKpr May 9, 2025
47bdcfc
prefix matching is preffered in search function
LSKpr May 9, 2025
5413a01
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 9, 2025
77d8ec0
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 9, 2025
aed5bb1
git stash fight
LSKpr May 9, 2025
8f37a32
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 9, 2025
1b3bd81
searchbar escape char bug fix
LSKpr May 9, 2025
f59d944
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 9, 2025
4fd77eb
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 9, 2025
35ed659
added srot by rating
LSKpr May 9, 2025
b326b11
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 9, 2025
1a55ad1
small design fix - ListView list
LSKpr May 9, 2025
39f011b
Merge branch 'main' of github.com:InferenceKTH/Find-My-Next-Course in…
LSKpr May 9, 2025
c8e8b16
small design fix - ListView looks cleaner now
LSKpr May 9, 2025
4787d64
popup new style + small fixes
LSKpr May 13, 2025
9979761
remove console.log in CoursePagePopup.jsx
LSKpr May 13, 2025
93953e9
Merge branch 'main' into fixes-and-sorting
LSKpr May 13, 2025
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
90 changes: 62 additions & 28 deletions my-app/src/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ export const model = {
scrollPosition: 0,
/* list of all course objects downloaded from the Firebase realtime database and stored locally as JSON object in this array */
courses: [],
departments : [],
departments: [],
locations: [],
// indexes: 0 -> overall rating; 1 -> difficulty; 2->teacher rating
avgRatings: [],
// model.avgRatings["IK1203"][0]
/* courses the user selected as their favourite */
favourites: [],
searchHistory:[],
searchHistory: [],
isReady: false,
/* this is a boolean flag showing that filtering options in the UI have changed, triggering the FilterPresenter to recalculate the filteredCourses[] */
filtersChange: false,
filtersChange: false,
/* this is a flag showing if the filteredCourses[] has changed (since FilterPresenter recalculated it), so now SearchBarPresenter needs to
recalculate currentSearch[] depending this updated list of courses */
filtersCalculated: false,
/* this is the array that FilterPresenter fills up with course objects, filtered from the model.courses[] */
filteredCourses: [],
filteredCourses: [],
/* JSON object containing all important parameters the FilterPresenter needs to calculate the filtered list of courses */
filterOptions: {
//apply-X-Filter boolean triggering flag wether corresponding filtering functions should run or not
Expand All @@ -41,9 +41,9 @@ export const model = {
level: ["PREPARATORY", "BASIC", "ADVANCED", "RESEARCH"], //the possible values for the array are: "PREPARATORY", "BASIC", "ADVANCED", "RESEARCH"
applyLanguageFilter: false,
language: "none", //the possible values for the string are: "none"/"english"/"swedish"/"both"
applyLocationFilter:false,
applyLocationFilter: false,
location: [], //the possible values for the array are: 'KTH Campus', 'KTH Kista', 'AlbaNova', 'KTH Flemingsberg', 'KTH Solna', 'KTH Södertälje', 'Handelshögskolan', 'KI Solna', 'Stockholms universitet', 'KONSTFACK'
applyCreditsFilter:true,
applyCreditsFilter: true,
creditMin: 0,
creditMax: 45,
applyDepartmentFilter: false,
Expand All @@ -59,34 +59,34 @@ export const model = {
_coursesListeners: [], // internal list of listeners

onCoursesSet(callback) {
this._coursesListeners.push(callback);
this._coursesListeners.push(callback);
},

_coursesListeners: [], // internal list of listeners
urlStackPointer: 0,

onCoursesSet(callback) {
this._coursesListeners.push(callback);
this._coursesListeners.push(callback);
},

setUser(user) {
if (!this.user)
this.user = user;
},

setCurrentSearch(searchResults){
setCurrentSearch(searchResults) {
this.currentSearch = searchResults;
},

setCurrentSearchText(text){
setCurrentSearchText(text) {
this.currentSearchText = text;
},

setScrollPosition(position) {
this.scrollPosition = position;
},

setCourses(courses){
setCourses(courses) {
this.courses = courses;
this._coursesListeners.forEach(cb => cb(courses));
},
Expand All @@ -106,20 +106,20 @@ export const model = {
console.error("Error adding course code to the history:", error);
}
},
setDepartments(departments){
setDepartments(departments) {
this.departments = departments;
},
setLocations(locations){
setLocations(locations) {
this.locations = locations;
},
setAverageRatings(ratings) {
this.avgRatings = ratings;
},
updateAverageRating(courseCode, rating){
if(this.avgRatings!= null)
updateAverageRating(courseCode, rating) {
if (this.avgRatings != null)
this.avgRatings[courseCode] = rating;
},
setFavourite(favorites){
setFavourite(favorites) {
this.favourites = favorites;
},

Expand Down Expand Up @@ -175,7 +175,7 @@ export const model = {
this.departments = Array.from(dep);
this.locations = Array.from(loc);
uploadDepartmentsAndLocations(this.departments, this.locations);

},
//for reviews
async addReview(courseCode, review) {
Expand All @@ -187,7 +187,7 @@ export const model = {
return false;
}
},

async getReviews(courseCode) {
try {
return await getReviewsForCourse(courseCode);
Expand All @@ -206,15 +206,15 @@ export const model = {
this.filtersCalculated = true;
},

setFilterOptions(options){
setFilterOptions(options) {
this.filterOptions = options; // do we want to set the flags? What about useEffect?
},

setApplyRemoveNullCourses() {
this.filterOptions.applyRemoveNullCourses = !this.filterOptions.applyRemoveNullCourses;
this.setFiltersChange();
},

setApplyRemoveNullCourses() {
this.filterOptions.applyRemoveNullCourses = !this.filterOptions.applyRemoveNullCourses;
this.setFiltersChange();
Expand Down Expand Up @@ -285,8 +285,8 @@ export const model = {
const sortedGrouped = Object.keys(grouped)
.sort()
.reduce((acc, key) => {
acc[key] = grouped[key].sort();
return acc;
acc[key] = grouped[key].sort();
return acc;
}, {});
const fields = Object.entries(sortedGrouped).map(([school, departments], index) => ({
id: index + 1,
Expand All @@ -295,12 +295,44 @@ export const model = {
}));
return fields;
},
async getAverageRating(courseCode) {
async getAverageRating(courseCode, option) {
const reviews = await getReviewsForCourse(courseCode);
if (!reviews || reviews.length === 0) return null;
const total = reviews.reduce((sum, review) => sum + (review.overallRating || 0), 0);
const avgRtg = (total / reviews.length).toFixed(1);
return avgRtg;

let validReviews = 0;
let total = 0;

switch (option) {
case "avg":
reviews.forEach(review => {
if (typeof review.overallRating === 'number') {
total += review.overallRating;
validReviews++;
}
});
break;
case "diff":
reviews.forEach(review => {
if (typeof review.difficultyRating === 'number') {
total += review.difficultyRating;
validReviews++;
}
});
break;
case "prof":
reviews.forEach(review => {
if (typeof review.professorRating === 'number') {
total += review.professorRating;
validReviews++;
}
});
break;
default:
return null;
}

if (validReviews === 0) return null;
return (total / validReviews).toFixed(1);
},

setPopupOpen(isOpen) {
Expand All @@ -326,17 +358,19 @@ export const model = {

handleUrlChange() {
let current_url = window.location.href;

let start_idx = indexOfNth(current_url, '/', 3) + 2;

if (start_idx > 0 && start_idx < current_url.length) {

let course_code = current_url.slice(start_idx);
let course = this.getCourse(course_code);
if (course) {
this.setSelectedCourse(course);
this.setPopupOpen(true);
}
this.urlStackPointer++;
} else if (start_idx > 0){
} else if (start_idx > 0) {
this.setPopupOpen(false);
}
}
Expand Down
4 changes: 2 additions & 2 deletions my-app/src/presenters/SearchbarPresenter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const SearchbarPresenter = observer(({ model }) => {

const fuseOptions = {
keys: [
{ name: 'code', weight: 0.6 },
{ name: 'name', weight: 0.3 },
{ name: 'code', weight: 0.5 },
{ name: 'name', weight: 0.4 },
{ name: 'description', weight: 0.1 },
],
threshold: 0.3141592653589793238, // adjust this for sensitivity
Expand Down
Loading