Skip to content

Commit d17a377

Browse files
daDevBoatkexanaDinoxhLSKprSailet03
authored
URL and prereq tree compatability fixes (#131)
* sidebar component add * tailwind workin, beggining page building * structure * fixed app * Main design layout * initial sidebar * courseView init * the course page initial tests * Make it run on my comuter * Tree without database integration * fixes * npm update * add to page * Biiiiig Refactoring * Broken version of prereq tree * Fixed not rendering anything. Still broken * Working v1 * handling #prereqs * Test * removed commented out code * More info expands now * More info expands now * More info expands now * Start coding on line 135 in PrereqTreePresenter Mr. PO * Prereqs colored and expands more info * added css styling * Fixed copy bug * Crash fix in PrerequisitePresenter.jsx * merge fix * Prereq tree compression, error handling, debuging, database update * Added null support (hopefully) * Bug fixes * Desplays periods * Bug finally fixed (hopefully) * Check if course exists before doing pop up * Set up for url handling * URL in progress * URL fix * Fix try 3 --------- Co-authored-by: kexana <deotsts@gmail.com> Co-authored-by: Sami Al Saati <sami.alsaati@hotmail.com> Co-authored-by: Kacper Lisik <lisik@kth.se> Co-authored-by: Elias Tosteberg <elias.tosteberg@gmail.com> Co-authored-by: Sailet03 <52610280+Sailet03@users.noreply.github.com>
1 parent 210b196 commit d17a377

File tree

6 files changed

+33
-38
lines changed

6 files changed

+33
-38
lines changed

my-app/src/model.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ export const model = {
6262
this._coursesListeners.push(callback);
6363
},
6464

65+
_coursesListeners: [], // internal list of listeners
66+
urlStackPointer: 0,
67+
68+
onCoursesSet(callback) {
69+
this._coursesListeners.push(callback);
70+
},
71+
6572
setUser(user) {
6673
if (!this.user)
6774
this.user = user;
@@ -297,14 +304,10 @@ export const model = {
297304
},
298305

299306
setPopupOpen(isOpen) {
300-
if (isOpen) {
301-
window.history.pushState({}, '', '/' + this.selectedCourse.code);
302-
}
303307
if (!isOpen) {
304308
let current_url = window.location.href;
305-
console.log(current_url);
306-
let end_idx = indexOfNth(current_url, '/', 3);
307-
if (end_idx >= 0 && end_idx < current_url.length - 1 && current_url.indexOf("#") == -1) {
309+
let end_index = indexOfNth(current_url, '/', 3);
310+
if (end_index + 1 != current_url.length) {
308311
window.history.back();
309312
}
310313
}
@@ -324,23 +327,18 @@ export const model = {
324327
handleUrlChange() {
325328
let current_url = window.location.href;
326329
let start_idx = indexOfNth(current_url, '/', 3) + 1;
327-
console.log(current_url)
328330

329331
if (start_idx > 0 && start_idx < current_url.length && current_url.indexOf("#") == -1) {
330332
let course_code = current_url.slice(start_idx);
331333
let course = this.getCourse(course_code);
332-
console.log(course_code)
333334
if (course) {
334-
console.log("ACTIVE")
335335
this.setSelectedCourse(course);
336336
this.setPopupOpen(true);
337337
}
338-
console.log("Forward");
339-
} else {
340-
console.log("Back")
338+
this.urlStackPointer++;
339+
} else if (start_idx > 0){
341340
this.setPopupOpen(false);
342341
}
343-
//console.log("back");
344342
}
345343

346344
};

my-app/src/presenters/ListViewPresenter.jsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,7 @@ const ListViewPresenter = observer(({ model }) => {
150150
setSortedCourses(sorted);
151151
}, [model.currentSearch, sortBy, sortDirection]);
152152

153-
154-
window.addEventListener('popstate', () => {
155-
model.handleUrlChange();
156-
});
157-
153+
158154
function indexOfNth(string, char, n) {
159155
let count = 0;
160156
for (let i = 0; i < string.length; i++) {
@@ -168,19 +164,22 @@ const ListViewPresenter = observer(({ model }) => {
168164
return -1;
169165
}
170166

167+
window.addEventListener('popstate', () => {
168+
model.handleUrlChange();
169+
});
170+
171171
model.onCoursesSet((courses) => {
172172
let current_url = window.location.href;
173-
if (indexOfNth(current_url, '/', 3) != current_url.length - 1) {
173+
let course_code = "";
174+
let start_index = indexOfNth(current_url, '/', 3) + 1;
175+
if (start_index > 1) {
176+
course_code = current_url.slice(start_index);
177+
}
178+
if (start_index != current_url.length && course_code.length >= 6) {
174179
window.history.replaceState({}, '', '/');
175-
/*
176-
setTimeout(() => {
177-
const newPath = '/' + current_url.slice(indexOfNth(current_url, '/', 3) + 1);
178-
window.history.pushState({}, '', newPath);
179-
}, 50);
180-
}
181-
*/
182-
model.handleUrlChange();
180+
window.history.pushState({}, '', '/' + course_code);
183181
}
182+
model.handleUrlChange();
184183
})
185184

186185
const preP = <PrerequisitePresenter

my-app/src/presenters/PrerequisitePresenter.jsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,6 @@ export const PrerequisitePresenter = observer((props) => {
215215
type: node_type,
216216
data: { label: name },
217217
style: {
218-
//padding: 0,
219-
//maxWidth: "100px",
220-
//display: 'inline-block',
221-
//justifyContent: 'center',
222-
//alignItems: 'center',
223218
zIndex: 0
224219
},
225220
position,
@@ -484,7 +479,9 @@ export const PrerequisitePresenter = observer((props) => {
484479
let copy = JSON.parse(JSON.stringify(props.selectedCourse.prerequisites));
485480
let courses_taken = [];
486481
if (localStorage.getItem("completedCourses") != null) {
487-
courses_taken = localStorage.getItem("completedCourses");
482+
for (let obj of localStorage.getItem("completedCourses")) {
483+
courses_taken.push(obj?.id);
484+
}
488485
}
489486
code_to_name = model.getCourseNames(courses_taken);
490487

my-app/src/views/Components/FavouriteDropdown.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const FavouritesDropdown = observer((props) => {
4040
onClick={() => {
4141
props.setSelectedCourse(course);
4242
props.setIsPopupOpen(true);
43+
window.history.pushState({}, '', '/' + course.code);
44+
4345
}}
4446
key={course.code}
4547
className="p-3 hover:bg-indigo-400/50 cursor-pointer flex justify-between items-center w-full border-b border-solid border-violet-400"
@@ -95,9 +97,6 @@ const FavouritesDropdown = observer((props) => {
9597
</div>
9698

9799
{/* Optional course popup */}
98-
<div className="relative z-50">
99-
{props.isPopupOpen && props.popup}
100-
</div>
101100
</div>
102101
);
103102
});

my-app/src/views/ListView.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function ListView(props) {
176176
onClick={() => {
177177
props.setSelectedCourse(course);
178178
props.setPopupOpen(true);
179-
//window.history.pushState({}, '', '/' + course.code);
179+
window.history.pushState({}, '', '/' + course.code);
180180
}}
181181
key={course.code}
182182
className="p-5 mb-3 hover:bg-blue-100 flex items-center border border-b-black border-solid w-full rounded-lg cursor-pointer"

my-app/src/views/SearchbarView.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ function SearchbarView(props) {
8989
{showFavourites && (
9090
<FavouritesDropdown
9191
{...props}
92-
onClick={(e) => e.stopPropagation()}
92+
onClick={
93+
(e) => e.stopPropagation()
94+
}
9395
/>
9496
)}
9597
</div>

0 commit comments

Comments
 (0)