@@ -93,6 +93,7 @@ import {
9393 CourseRegistrationDoc ,
9494 DataLayerProvider ,
9595 UserDBInterface ,
96+ ClassroomDBInterface ,
9697} from ' @vue-skuilder/db' ;
9798import { SessionController , StudySessionRecord } from ' @vue-skuilder/db' ;
9899import { newInterval } from ' @vue-skuilder/db' ;
@@ -158,7 +159,15 @@ export default defineComponent({
158159 },
159160 },
160161
161- emits: [' session-finished' , ' session-started' , ' card-loaded' , ' card-response' , ' time-changed' ],
162+ emits: [
163+ ' session-finished' ,
164+ ' session-started' ,
165+ ' card-loaded' ,
166+ ' card-response' ,
167+ ' time-changed' ,
168+ ' session-prepared' ,
169+ ' session-error' ,
170+ ],
162171
163172 data() {
164173 return {
@@ -224,7 +233,9 @@ export default defineComponent({
224233
225234 async created() {
226235 this .userCourseRegDoc = await this .user .getCourseRegistrationsDoc ();
227- this .initSession ();
236+ console .log (' [StudySession] Created lifecycle hook - starting initSession' );
237+ await this .initSession ();
238+ console .log (' [StudySession] InitSession completed in created hook' );
228239 },
229240
230241 methods: {
@@ -271,58 +282,84 @@ export default defineComponent({
271282 },
272283
273284 async initSession() {
274- console .log (` [StudySession] starting study session w/ sources: ${JSON .stringify (this .contentSources )} ` );
275-
276- this .sessionContentSources = (
277- await Promise .all (
278- this .contentSources .map (async (s ) => {
279- try {
280- return await getStudySource (s , this .user );
281- } catch (e ) {
282- console .error (` Failed to load study source: ${s .type }/${s .id } ` , e );
283- return null ;
284- }
285- })
286- )
287- ).filter ((s ) => s !== null );
285+ let sessionClassroomDBs: ClassroomDBInterface [] = [];
286+ try {
287+ console .log (` [StudySession] starting study session w/ sources: ${JSON .stringify (this .contentSources )} ` );
288+ console .log (' [StudySession] Beginning preparation process' );
289+
290+ this .sessionContentSources = (
291+ await Promise .all (
292+ this .contentSources .map (async (s ) => {
293+ try {
294+ return await getStudySource (s , this .user );
295+ } catch (e ) {
296+ console .error (` Failed to load study source: ${s .type }/${s .id } ` , e );
297+ return null ;
298+ }
299+ })
300+ )
301+ ).filter ((s ) => s !== null );
288302
289- this .timeRemaining = this .sessionTimeLimit * 60 ;
303+ this .timeRemaining = this .sessionTimeLimit * 60 ;
290304
291- const sessionClassroomDBs = await Promise .all (
292- this .contentSources
293- .filter ((s ) => s .type === ' classroom' )
294- .map (async (c ) => await this .dataLayer .getClassroomDB (c .id , ' student' ))
295- );
305+ sessionClassroomDBs = await Promise .all (
306+ this .contentSources
307+ .filter ((s ) => s .type === ' classroom' )
308+ .map (async (c ) => await this .dataLayer .getClassroomDB (c .id , ' student' ))
309+ );
296310
297- sessionClassroomDBs .forEach ((db ) => {
298- // db.setChangeFcn(this.handleClassroomMessage());
299- });
311+ sessionClassroomDBs .forEach ((db ) => {
312+ // db.setChangeFcn(this.handleClassroomMessage());
313+ });
300314
301- this .sessionController = new SessionController (this .sessionContentSources , 60 * this .sessionTimeLimit );
302- this .sessionController .sessionRecord = this .sessionRecord ;
315+ this .sessionController = new SessionController (this .sessionContentSources , 60 * this .sessionTimeLimit );
316+ this .sessionController .sessionRecord = this .sessionRecord ;
303317
304- await this .sessionController .prepareSession ();
305- this .intervalHandler = setInterval (this .tick , 1000 );
318+ await this .sessionController .prepareSession ();
319+ this .intervalHandler = setInterval (this .tick , 1000 );
306320
307- this .sessionPrepared = true ;
321+ this .sessionPrepared = true ;
308322
309- this .contentSources
310- .filter ((s ) => s .type === ' course' )
311- .forEach (
312- async (c ) => (this .courseNames [c .id ] = (await this .dataLayer .getCoursesDB ().getCourseConfig (c .id )).name )
313- );
323+ console .log (' [StudySession] Session preparation complete, emitting session-prepared event' );
324+ this .$emit (' session-prepared' );
325+ console .log (' [StudySession] Event emission completed' );
326+ } catch (error ) {
327+ console .error (' [StudySession] Error during session preparation:' , error );
328+ // Notify parent component about the error
329+ this .$emit (' session-error' , { message: ' Failed to prepare study session' , error });
330+ }
314331
315- console .log (` [StudySession] Session created:
316- ${this .sessionController .toString ()}
317- User courses: ${this .contentSources
332+ try {
333+ this .contentSources
318334 .filter ((s ) => s .type === ' course' )
319- .map ((c ) => c .id )
320- .toString ()}
321- User classrooms: ${sessionClassroomDBs .map ((db ) => db ._id )}
322- ` );
335+ .forEach (
336+ async (c ) => (this .courseNames [c .id ] = (await this .dataLayer .getCoursesDB ().getCourseConfig (c .id )).name )
337+ );
338+
339+ console .log (` [StudySession] Session created:
340+ ${this .sessionController ?.toString () || ' Session controller not initialized' }
341+ User courses: ${this .contentSources
342+ .filter ((s ) => s .type === ' course' )
343+ .map ((c ) => c .id )
344+ .toString ()}
345+ User classrooms: ${sessionClassroomDBs .map ((db : any ) => db ._id ).toString () || ' No classrooms' }
346+ ` );
347+ } catch (error ) {
348+ console .error (' [StudySession] Error during final session setup:' , error );
349+ }
323350
324- this .$emit (' session-started' );
325- this .loadCard (this .sessionController .nextCard ());
351+ if (this .sessionController ) {
352+ try {
353+ this .$emit (' session-started' );
354+ this .loadCard (this .sessionController .nextCard ());
355+ } catch (error ) {
356+ console .error (' [StudySession] Error loading next card:' , error );
357+ this .$emit (' session-error' , { message: ' Failed to load study card' , error });
358+ }
359+ } else {
360+ console .error (' [StudySession] Cannot load card: session controller not initialized' );
361+ this .$emit (' session-error' , { message: ' Study session initialization failed' });
362+ }
326363 },
327364
328365 countCardViews(course_id : string , card_id : string ): number {
0 commit comments