Skip to content
This repository was archived by the owner on Jul 27, 2024. It is now read-only.

Commit ffc6c84

Browse files
committed
WIP load plan from link
1 parent 851f806 commit ffc6c84

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

Closure_Front_End/src/router/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ const routes = [
2121
name: 'Scrape',
2222
component: CourseImport,
2323
beforeEnter: routeGuard
24+
},
25+
{
26+
path: '/plans/:plan_id',
27+
name: 'Course Plan',
28+
component: Home
2429
}
2530
]
2631

Closure_Front_End/src/views/Home.vue

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
</template>
2424

2525
<script>
26-
import { ref, inject, provide } from "vue";
26+
import { ref, inject, provide, watch } from "vue";
27+
import { useRoute } from "vue-router";
2728
import Year from "../components/Year.vue";
2829
import Navigation from "../components/Navigation.vue";
2930
import CourseDetail from "../components/CourseDetail.vue";
3031
import ProgressBox from "../components/ProgressBox.vue";
31-
import { courses } from "@/course-store.js";
32+
import { courses, loadPlan } from "@/course-store.js";
3233
3334
const years = [
3435
{ id: 1, name: "שנה א" },
@@ -42,14 +43,45 @@ export default {
4243
components: { Year, Navigation, CourseDetail, ProgressBox },
4344
setup() {
4445
const selectedCourse = ref(null);
45-
const selectCourse = (course) => (selectedCourse.value = course);
46-
const auth = inject("auth")
47-
provide("selectCourse", selectCourse)
46+
provide("selectCourse", (course) => (selectedCourse.value = course));
47+
const auth = inject("auth");
48+
const loadingPlan = ref(false);
49+
const failDueToAuth = ref(false);
50+
51+
const onEnter = async (to) => {
52+
if (to.name === "Course Plan" && to.params.plan_id !== undefined) {
53+
console.log("loadPlan due to route change, target params:", to);
54+
loadingPlan.value = true;
55+
try {
56+
await loadPlan(to.params.plan_id);
57+
} catch (ex) {
58+
if (ex.response?.status == 404) {
59+
console.log("not found")
60+
failDueToAuth.value = true
61+
}
62+
63+
} finally {
64+
loadingPlan.value = false;
65+
}
66+
}
67+
};
68+
const route = useRoute();
69+
onEnter(route);
70+
71+
watch(
72+
() => route.params.plan_id,
73+
async (to) => {
74+
await onEnter(to);
75+
}
76+
);
77+
4878
return {
4979
years,
5080
selectedCourse,
5181
courses,
52-
auth
82+
auth,
83+
failDueToAuth,
84+
loadingPlan
5385
};
5486
},
5587
};

0 commit comments

Comments
 (0)