@@ -6,16 +6,24 @@ import { SearchbarPresenter } from './SearchbarPresenter.jsx';
66/* FilterPresenter is responsible for applying the logic necessary to filter out the courses from the overall list */
77const FilterPresenter = observer ( ( { model } ) => {
88 /* global variable for the scope of this presenter, all the smaller functions depend on it instead of passing it back and forth as params */
9- var localFilteredCourses = [ ] ; //might need to declare out of scope. idk js
9+ var localFilteredCourses = [ ] ;
1010
11+ /* functions declared here are generally things the main function of this observer takes and runs if the given filters are enabled,
12+ * this is determined through model.filterOptions.apply*Insert filter name* flags.
13+ * This presenter should be changed such that it uses side-effects instead model.filtersChange flag, since
14+ */
1115
16+ /* functions */
1217 function applyTranscriptEligibility ( ) {
1318 if ( localFilteredCourses . length == 0 )
1419 return ;
1520
16- /* */
21+ /* this should be either weak/moderate/strong */
1722 const eligibilitytype = model . filterOptions . eligibility ;
1823
24+ /* I am doing this trick in a multitude of filters, essentially the best fitting courses should appear first in the
25+ * list view on the right side, so we just filter for those and at the very end merge them back together into a single array
26+ */
1927 let strongcourses = [ ] ;
2028 let zerocourses = [ ] ;
2129 let moderatecourses = [ ] ;
@@ -55,6 +63,7 @@ const FilterPresenter = observer(({ model }) => {
5563
5664 } ) ;
5765
66+ /* If user selects strong matching he should get all courses which might be strongly fitting (so strong courses and zero/missing prereq courses) */
5867 switch ( eligibilitytype ) {
5968 case "strong" :
6069 {
@@ -73,7 +82,7 @@ const FilterPresenter = observer(({ model }) => {
7382 }
7483 default :
7584 {
76- console . log ( "Error: somehow we got into a state where model.eligibility is no \"strong\"/\"moderate\"/\"weak\"." ) ;
85+ console . log ( "Error: somehow we got into a state where model.eligibility is not either \"strong\"/\"moderate\"/\"weak\"." ) ;
7786 localFilteredCourses = [ ] ;
7887 break ;
7988 }
@@ -182,8 +191,6 @@ const FilterPresenter = observer(({ model }) => {
182191 //course?.language.english (true/false/undefined)
183192 //course?.language.swedish (true/false/undefined)
184193
185- //console.log(data);
186-
187194 switch ( languages ) {
188195 case "none" :
189196 {
@@ -196,8 +203,7 @@ const FilterPresenter = observer(({ model }) => {
196203 try {
197204 return ( course ?. language ?. english === true ) ;
198205 } catch ( error ) {
199- console . log ( course ) ;
200- console . log ( "BIG ERROR" , error ) ;
206+ console . log ( "BIG ERROR" , error , course ) ;
201207 return false ;
202208 }
203209
@@ -207,8 +213,7 @@ const FilterPresenter = observer(({ model }) => {
207213 try {
208214 return ( course ?. language === undefined ) ;
209215 } catch ( error ) {
210- console . log ( course ) ;
211- console . log ( "BIG ERROR" ) ;
216+ console . log ( "BIG ERROR" , error , course ) ;
212217 return false ;
213218 }
214219
@@ -221,8 +226,7 @@ const FilterPresenter = observer(({ model }) => {
221226 try {
222227 return ( course ?. language ?. swedish === true ) ;
223228 } catch ( error ) {
224- console . log ( course ) ;
225- console . log ( "BIG ERROR" ) ;
229+ console . log ( "BIG ERROR" , error , course ) ;
226230 return false ;
227231 }
228232
@@ -232,8 +236,7 @@ const FilterPresenter = observer(({ model }) => {
232236 try {
233237 return ( course ?. language === undefined ) ;
234238 } catch ( error ) {
235- console . log ( course ) ;
236- console . log ( "BIG ERROR" ) ;
239+ console . log ( "BIG ERROR" , error , course ) ;
237240 return false ;
238241 }
239242
@@ -246,8 +249,7 @@ const FilterPresenter = observer(({ model }) => {
246249 try {
247250 return ( ( course ?. language ?. english === true ) && ( course ?. language ?. swedish === true ) ) ;
248251 } catch ( error ) {
249- console . log ( course ) ;
250- console . log ( "BIG ERROR" ) ;
252+ console . log ( "BIG ERROR" , error , course ) ;
251253 return false ;
252254 }
253255
@@ -258,8 +260,7 @@ const FilterPresenter = observer(({ model }) => {
258260 return ( ( ( course ?. language ?. english === true ) && ( course ?. language ?. swedish === false ) )
259261 || ( ( course ?. language ?. english === false ) && ( course ?. language ?. swedish === true ) ) ) ;
260262 } catch ( error ) {
261- console . log ( course ) ;
262- console . log ( "BIG ERROR" ) ;
263+ console . log ( "BIG ERROR" , error , course ) ;
263264 return false ;
264265 }
265266
@@ -269,8 +270,7 @@ const FilterPresenter = observer(({ model }) => {
269270 try {
270271 return ( course ?. language === undefined ) ;
271272 } catch ( error ) {
272- console . log ( course ) ;
273- console . log ( "BIG ERROR" ) ;
273+ console . log ( "BIG ERROR" , error , course ) ;
274274 return false ;
275275 }
276276
@@ -293,25 +293,9 @@ const FilterPresenter = observer(({ model }) => {
293293
294294 localFilteredCourses = localFilteredCourses . filter ( course => levels . includes ( course ?. academicLevel ) ) ;
295295
296- /*
297- let levels = model.filterOptions.level;
298- let stayingCourses = [];
299-
300- for(let i=0; i<localFilteredCourses.length; i++){
301- let stay = false;
302- for(let j=0; j<levels.length; j++){
303- if(localFilteredCourses[i].academicLevel === levels[j]){
304- stay = true;
305- break;
306- }
307- }
308- if(stay) stayingCourses.push(localFilteredCourses[i]);
309- }
310- localFilteredCourses = [...stayingCourses];*/
311296 }
312297
313298 function updateDepartments ( ) {
314- console . log ( model . filterOptions . department ) ;
315299 const departments = model . filterOptions . department ;
316300 let bestCourses = [ ] ;
317301 let worstCourses = [ ] ;
@@ -329,7 +313,7 @@ const FilterPresenter = observer(({ model }) => {
329313 try {
330314 return ( course ?. department === undefined ) ;
331315 } catch ( error ) {
332- console . log ( "BIG ERROR" , error ) ;
316+ console . log ( "BIG ERROR" , error , course ) ;
333317 return false ;
334318 }
335319
@@ -338,6 +322,10 @@ const FilterPresenter = observer(({ model }) => {
338322 localFilteredCourses = [ ...bestCourses , ...worstCourses ] ;
339323 }
340324
325+ /* Function that deals with removing the courses that have no properties or have null properties in the categories the user
326+ * using for filtering. The "null" check is a remainder from a version where we didn't use the ?. property accessing yet,
327+ * should be able to be removed without problem in the future.
328+ */
341329 function updateNoNullcourses ( ) {
342330 let local = [ ...localFilteredCourses ] ;
343331
@@ -381,6 +369,7 @@ const FilterPresenter = observer(({ model }) => {
381369 localFilteredCourses = [ ...local ] ;
382370 }
383371
372+ /* function that should run every single time the model changes (see note below) */
384373 async function run ( ) {
385374 if ( model . courses . length == 0 ) {
386375 return ;
@@ -416,10 +405,13 @@ const FilterPresenter = observer(({ model }) => {
416405 model . filteredCourses = [ ...localFilteredCourses ] ;
417406 model . filtersChange = false ;
418407 model . setFiltersCalculated ( ) ;
419- //console.log("filtered objects number of elements: ", model.filteredCourses.length);
420408 }
421409 }
422410
411+ /* the problem is that unless using sideeffects, the run() not being async and/or it setting the filterschange = false very early can mean
412+ * that 0 courses will get put into the model.filtered courses (which is the list of courses getting passed to search, and then listview)
413+ * therefore TODO: rework it to stop using this dumb flags we started before learning anything about react,observers,js
414+ */
423415 run ( ) ;
424416
425417} ) ;
0 commit comments