techstartucalgary/lifeline

History Bug at `/app`

Closed this issue · 0 comments

To recreate:

  • Have courses stored in localStorage (upload something)
  • Exit the page and reload it at / (landing page)
  • Click "get started" button
  • You are now on /app. Click the back arrow of your browser

Expected behaviour: return to landing page /
Actual behaviour: have to click 3 times to return to landing page /

Probably something to do with with

useEffect(() => {
// Update history when current course changes
if (currentCourse === null) {
history.pushState(null, "", "/app");
} else {
history.pushState(null, "", `/app/${currentCourse.key}`);
}
}, [currentCourse]);

interacting with
useEffect(() => {
// Load courses from local storage
const foundCourses = localStorage.getItem("courses");
if (!foundCourses) return;
const parsedCourses: Courses = JSON.parse(foundCourses).map(parseCourse);
setCourses(parsedCourses);
coursesRef.current = parsedCourses;

as I think it was introduced in #202 but I'm not sure.