Skip to content

Commit da166c7

Browse files
applied filters into the search function using flags in the model, will have to refine more in the filters, but this is great for the demo
1 parent 58d4925 commit da166c7

5 files changed

Lines changed: 18 additions & 7 deletions

File tree

my-app/src/model.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const model = {
1010
favourites: [],
1111
isReady: false,
1212
filtersChange: false,
13+
filtersCalculated: false,
1314
filteredCourses: [],
1415
filterOptions: {
1516
applyTranscriptFilter: true,
@@ -108,6 +109,10 @@ export const model = {
108109
setFiltersChange() {
109110
this.filtersChange = true;
110111
},
112+
113+
setFiltersCalculated() {
114+
this.filtersCalculated = true;
115+
},
111116

112117
updateLevelFilter(level) {
113118
this.filterOptions.level = level;

my-app/src/pages/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { model } from '/src/model.js';
99

1010
function MainAppLayout({ model }) {
1111
return (
12-
<div className="flex h-screen w-screen">
12+
<div className="flex h-screen w-screen overflow-hidden">
1313
<FilterPresenter model={model} />
1414
<div className="flex-auto w-40% h-full bg-gradient-to-t from-[#4f3646] to-[#6747c0]">
1515
<SidebarPresenter model={model} />

my-app/src/presenters/FilterPresenter.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ const FilterPresenter = observer(({ model }) => {
2828
//console.log(course?.prerequisites);
2929
if(course?.prerequisites && (course.prerequisites !== "null"))
3030
var resultEligibility = eligibility(storedFinishedCourses, course?.prerequisites);
31-
else{
32-
//zerocourses.push(course);
31+
else{ // {strong: , zero: , moderate: , weak: }
32+
zerocourses.push(course);
3333
return;
3434
}
3535
if(resultEligibility.strong){
@@ -292,6 +292,7 @@ const FilterPresenter = observer(({ model }) => {
292292

293293
model.filteredCourses = [...localFilteredCourses];
294294
model.filtersChange = false;
295+
model.setFiltersCalculated();
295296
console.log("filtered objects number of elements: ", model.filteredCourses.length);
296297
}
297298
});

my-app/src/presenters/SearchbarPresenter.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const SearchbarPresenter = observer(({ model }) => {
1111
//model.filteredCourses is essentially a smaller subset of model.courses, if theres no filters, it should be the same
1212
console.log("---------------search recalculated");
1313
console.log("filtered courses length: ", model.filteredCourses.length);
14-
const searchResults = model.courses.filter(course =>
14+
const searchResults = model.filteredCourses.filter(course =>
1515
course.code.toLowerCase().includes(query.toLowerCase()) ||
1616
course.name.toLowerCase().includes(query.toLowerCase()) ||
1717
course.description.toLowerCase().includes(query.toLowerCase())
@@ -61,6 +61,11 @@ const SearchbarPresenter = observer(({ model }) => {
6161
prerequisiteTree={preP}
6262
/>;
6363

64+
if(model.filtersCalculated){
65+
searchCourses("");
66+
model.filtersCalculated = false;
67+
}
68+
6469
return (
6570
<SearchbarView
6671
model={model}

my-app/src/views/ListView.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import 'ldrs/react/Quantum.css';
44
import InfiniteScroll from 'react-infinite-scroll-component';
55

66
function ListView(props) {
7-
const coursesToDisplay =
8-
(props.searchResults && props.searchResults.length > 0
7+
const coursesToDisplay = props.searchResults;
8+
/*(props.searchResults && props.searchResults.length > 0
99
? props.searchResults
10-
: props.courses) || [];
10+
: props.courses) || [];*/
1111

1212
const [displayedCourses, setDisplayedCourses] = useState([]);
1313
const [hasMore, setHasMore] = useState(true);

0 commit comments

Comments
 (0)