Skip to content

Commit 64213aa

Browse files
committed
Filters are persistant - they just don't update bc Deo needs to fix the UI...
1 parent 5df4e5d commit 64213aa

2 files changed

Lines changed: 31 additions & 44 deletions

File tree

my-app/firebase.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,20 @@ export function connectToFirebase(model) {
3030

3131
// setting missing
3232
// also save filters to local storage
33-
//localStorage.setItem("filterOptions", filterOptions);
34-
const options = localStorage.getItem("filterOptions");
35-
if (options) {
36-
model.setFilterOptions(options);
37-
console.log("Restore options from local storage");
38-
}
33+
//
34+
const options = JSON.parse(localStorage.getItem("filterOptions"));
35+
if (options) {
36+
model.setFilterOptions(options);
37+
console.log("Restore options from local storage");
38+
}
39+
40+
reaction(
41+
() => ({filterOptions: JSON.stringify(model.filterOptions)}),
42+
// eslint-disable-next-line no-unused-vars
43+
({filterOptions}) => {
44+
localStorage.setItem("filterOptions", filterOptions);
45+
}
46+
);
3947

4048
onAuthStateChanged(auth, (user) => {
4149
if (user) {
@@ -61,7 +69,7 @@ async function firebaseToModel(model) {
6169
model.setCurrentSearchText(data.currentSearchText);
6270
// if (data.scrollPosition)
6371
// model.setScrollPosition(data.scrollPosition);
64-
if (data.filterOptions) model.setFilterOptions(data.filterOptions);
72+
// if (data.filterOptions) model.setFilterOptions(data.filterOptions);
6573
noUpload = false;
6674
});
6775
}
@@ -72,7 +80,7 @@ export function syncModelToFirebase(model) {
7280
userId: model?.user.uid,
7381
favourites: toJS(model.favourites),
7482
currentSearchText: toJS(model.currentSearchText),
75-
filterOptions: toJS(model.filterOptions),
83+
// filterOptions: toJS(model.filterOptions),
7684
// Add more per-user attributes here
7785
}),
7886
// eslint-disable-next-line no-unused-vars
@@ -82,7 +90,7 @@ export function syncModelToFirebase(model) {
8290
const dataToSync = {
8391
favourites,
8492
currentSearchText,
85-
filterOptions,
93+
// filterOptions,
8694
};
8795

8896
set(userRef, dataToSync)

my-app/src/model.js

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,16 @@ export const model = {
1818
applyTranscriptFilter: true,
1919
eligibility: "weak", //the possible values for the string are: "weak"/"moderate"/"strong"
2020
applyLevelFilter: true,
21-
level: ["PREPARATORY", "BASIC", "ADVANCED", "RESEARCH"], //the possible values for the array are: "PREPARATORY", "BASIC", "ADVANCED", "RESEARCH"
21+
level: [], //the possible values for the array are: "PREPARATORY", "BASIC", "ADVANCED", "RESEARCH"
2222
applyLanguageFilter: true,
2323
language: "none", //the possible values for the string are: "none"/"english"/"swedish"/"both"
2424
applyLocationFilter:true,
2525
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'
2626
applyCreditsFilter:true,
2727
creditMin: 0,
2828
creditMax: 45,
29-
applyDepartmentFilter: true,
30-
department: ["EECS/Computational Science and Technology", "EECS/Theoretical Computer Science", "EECS/Electric Power and Energy Systems", "EECS/Network and Systems Engineering",
31-
"ITM/Learning in Engineering Sciences", "ITM/Industrial Economics and Management", "ITM/Energy Systems", "ITM/Integrated Product Development and Design", "ITM/SKD GRU",
32-
"SCI/Mathematics", "SCI/Applied Physics", "SCI/Mechanics", "SCI/Aeronautical and Vehicle Engineering",
33-
"ABE/Sustainability and Environmental Engineering", "ABE/Concrete Structures", "ABE/Structural Design & Bridges", "ABE/History of Science, Technology and Environment", ],
34-
applyRemoveNullCourses: false
29+
applyDepartmentFilter:false,
30+
department: []
3531
},
3632

3733
setUser(user) {
@@ -88,17 +84,15 @@ export const model = {
8884
entries.forEach(entry => {
8985
const course = {
9086
code: entry[1].code,
91-
name: entry[1]?.name ?? "null",
92-
location: entry[1]?.location ?? "null",
93-
department: entry[1]?.department ?? "null",
94-
language: entry[1]?.language ?? "null",
95-
description: entry[1]?.description ?? "null",
96-
academicLevel: entry[1]?.academic_level ?? "null",
97-
period: entry[1]?.period ?? "null",
87+
name: entry[1]?.name ?? "",
88+
location: entry[1]?.location ?? "",
89+
department: entry[1]?.department ?? "",
90+
language: entry[1]?.language ?? "",
91+
description: entry[1]?.description ?? "",
92+
academicLevel: entry[1]?.academic_level ?? "",
93+
period: entry[1]?.period ?? "",
9894
credits: entry[1]?.credits ?? 0,
99-
prerequisites: entry[1]?.prerequisites ?? "null",
100-
prerequisites_text: entry[1]?.prerequisites_text ?? "null",
101-
learning_outcomes: entry[1]?.learning_outcomes ?? "null"
95+
prerequisites: entry[1]?.prerequisites ?? "",
10296
};
10397
this.addCourse(course);
10498
});
@@ -135,11 +129,6 @@ export const model = {
135129
this.filterOptions = options; // do we want to set the flags? What about useEffect?
136130
},
137131

138-
setApplyRemoveNullCourses() {
139-
this.filterOptions.applyRemoveNullCourses = !this.filterOptions.applyRemoveNullCourses;
140-
this.setFiltersChange();
141-
},
142-
143132
updateLevelFilter(level) {
144133
this.filterOptions.level = level;
145134
},
@@ -157,10 +146,6 @@ export const model = {
157146
this.filterOptions.eligibility = eligibility;
158147
},
159148

160-
updateDepartmentFilter(department) {
161-
this.filterOptions.department = department;
162-
},
163-
164149
//setters for the filter options
165150
setApplyTranscriptFilter(transcriptFilterState) {
166151
this.filterOptions.applyTranscriptFilter = transcriptFilterState;
@@ -177,16 +162,10 @@ export const model = {
177162
setApplyCreditsFilter(creditsFilterState) {
178163
this.filterOptions.applyCreditsFilter = creditsFilterState;
179164
},
180-
setApplyDepartmentFilter(departmentFilterState) {
181-
this.filterOptions.applyDepartmentFilter = departmentFilterState;
182-
},
165+
// setApplyDepartmentFilter(departmentFilterState) {
166+
// this.filterOptions.applyDepartmentFilter = departmentFilterState;
167+
// },
183168

184-
async getAverageRating(courseCode) {
185-
const reviews = await getReviewsForCourse(courseCode);
186-
if (!reviews || reviews.length === 0) return null;
187-
const total = reviews.reduce((sum, review) => sum + (review.overallRating || 0), 0);
188-
return (total / reviews.length).toFixed(1);
189-
},
190169

191170

192171
};

0 commit comments

Comments
 (0)