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" ;
2728import Year from " ../components/Year.vue" ;
2829import Navigation from " ../components/Navigation.vue" ;
2930import CourseDetail from " ../components/CourseDetail.vue" ;
3031import ProgressBox from " ../components/ProgressBox.vue" ;
31- import { courses } from " @/course-store.js" ;
32+ import { courses , loadPlan } from " @/course-store.js" ;
3233
3334const 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