@@ -158,7 +158,7 @@ export default defineComponent({
158158 },
159159 },
160160
161- emits: [' session-finished' , ' session-started' , ' card-loaded' , ' card-response' , ' time-changed' ],
161+ emits: [' session-finished' , ' session-started' , ' card-loaded' , ' card-response' , ' time-changed' , ' session-prepared ' , ' session-error ' ],
162162
163163 data() {
164164 return {
@@ -224,7 +224,9 @@ export default defineComponent({
224224
225225 async created() {
226226 this .userCourseRegDoc = await this .user .getCourseRegistrationsDoc ();
227- this .initSession ();
227+ console .log (' [StudySession] Created lifecycle hook - starting initSession' );
228+ await this .initSession ();
229+ console .log (' [StudySession] InitSession completed in created hook' );
228230 },
229231
230232 methods: {
@@ -271,58 +273,84 @@ export default defineComponent({
271273 },
272274
273275 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 );
288-
289- this .timeRemaining = this .sessionTimeLimit * 60 ;
290-
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- );
296-
297- sessionClassroomDBs .forEach ((db ) => {
298- // db.setChangeFcn(this.handleClassroomMessage());
299- });
276+ let sessionClassroomDBs = [];
277+ try {
278+ console .log (` [StudySession] starting study session w/ sources: ${JSON .stringify (this .contentSources )} ` );
279+ console .log (' [StudySession] Beginning preparation process' );
280+
281+ this .sessionContentSources = (
282+ await Promise .all (
283+ this .contentSources .map (async (s ) => {
284+ try {
285+ return await getStudySource (s , this .user );
286+ } catch (e ) {
287+ console .error (` Failed to load study source: ${s .type }/${s .id } ` , e );
288+ return null ;
289+ }
290+ })
291+ )
292+ ).filter ((s ) => s !== null );
300293
301- this .sessionController = new SessionController (this .sessionContentSources , 60 * this .sessionTimeLimit );
302- this .sessionController .sessionRecord = this .sessionRecord ;
294+ this .timeRemaining = this .sessionTimeLimit * 60 ;
303295
304- await this .sessionController .prepareSession ();
305- this .intervalHandler = setInterval (this .tick , 1000 );
296+ sessionClassroomDBs = await Promise .all (
297+ this .contentSources
298+ .filter ((s ) => s .type === ' classroom' )
299+ .map (async (c ) => await this .dataLayer .getClassroomDB (c .id , ' student' ))
300+ );
306301
307- this .sessionPrepared = true ;
302+ sessionClassroomDBs .forEach ((db ) => {
303+ // db.setChangeFcn(this.handleClassroomMessage());
304+ });
308305
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- );
306+ this .sessionController = new SessionController (this .sessionContentSources , 60 * this .sessionTimeLimit );
307+ this .sessionController .sessionRecord = this .sessionRecord ;
308+
309+ await this .sessionController .prepareSession ();
310+ this .intervalHandler = setInterval (this .tick , 1000 );
311+
312+ this .sessionPrepared = true ;
313+
314+ console .log (' [StudySession] Session preparation complete, emitting session-prepared event' );
315+ this .$emit (' session-prepared' );
316+ console .log (' [StudySession] Event emission completed' );
317+ } catch (error ) {
318+ console .error (' [StudySession] Error during session preparation:' , error );
319+ // Notify parent component about the error
320+ this .$emit (' session-error' , { message: ' Failed to prepare study session' , error });
321+ }
314322
315- console .log (` [StudySession] Session created:
316- ${this .sessionController .toString ()}
317- User courses: ${this .contentSources
323+ try {
324+ this .contentSources
318325 .filter ((s ) => s .type === ' course' )
319- .map ((c ) => c .id )
320- .toString ()}
321- User classrooms: ${sessionClassroomDBs .map ((db ) => db ._id )}
322- ` );
326+ .forEach (
327+ async (c ) => (this .courseNames [c .id ] = (await this .dataLayer .getCoursesDB ().getCourseConfig (c .id )).name )
328+ );
329+
330+ console .log (` [StudySession] Session created:
331+ ${this .sessionController ?.toString () || ' Session controller not initialized' }
332+ User courses: ${this .contentSources
333+ .filter ((s ) => s .type === ' course' )
334+ .map ((c ) => c .id )
335+ .toString ()}
336+ User classrooms: ${sessionClassroomDBs .map ((db ) => db ._id ).toString () || ' No classrooms' }
337+ ` );
338+ } catch (error ) {
339+ console .error (' [StudySession] Error during final session setup:' , error );
340+ }
323341
324- this .$emit (' session-started' );
325- this .loadCard (this .sessionController .nextCard ());
342+ if (this .sessionController ) {
343+ try {
344+ this .$emit (' session-started' );
345+ this .loadCard (this .sessionController .nextCard ());
346+ } catch (error ) {
347+ console .error (' [StudySession] Error loading next card:' , error );
348+ this .$emit (' session-error' , { message: ' Failed to load study card' , error });
349+ }
350+ } else {
351+ console .error (' [StudySession] Cannot load card: session controller not initialized' );
352+ this .$emit (' session-error' , { message: ' Study session initialization failed' });
353+ }
326354 },
327355
328356 countCardViews(course_id : string , card_id : string ): number {
0 commit comments