@@ -69,45 +69,85 @@ class CourseManager {
6969 }
7070
7171 /**
72- * 各コースのチャレンジデータを読み込み
72+ * 各コースのチャレンジデータを読み込み(遅延読み込み対応)
7373 */
7474 async loadChallengeData ( ) {
75+ // 遅延読み込み: 現在選択されているコースのみ読み込み
76+ const selectedCourseId = this . progressManager ?. getSelectedCourse ( ) ;
77+
7578 const challengeFiles = {
7679 'sql-basics' : 'slides/challenges.json' ,
7780 'db-fundamentals' : 'slides/db-fundamentals-challenges.json' ,
7881 'big-data-basics' : 'slides/big-data-basics-challenges.json'
7982 } ;
8083
81- for ( const [ courseId , filePath ] of Object . entries ( challengeFiles ) ) {
82- try {
83- const response = await fetch ( filePath ) ;
84- if ( response . ok ) {
85- this . challengeData [ courseId ] = await response . json ( ) ;
86- } else {
87- console . warn ( `チャレンジファイルが見つかりません: ${ filePath } ` ) ;
88- this . challengeData [ courseId ] = [ ] ;
89- }
90- } catch ( error ) {
91- console . error ( `チャレンジデータ読み込みエラー (${ courseId } ):` , error ) ;
84+ // 選択されたコースがある場合は、そのコースのみ読み込み
85+ if ( selectedCourseId && challengeFiles [ selectedCourseId ] ) {
86+ await this . loadCourseChallenge ( selectedCourseId , challengeFiles [ selectedCourseId ] ) ;
87+ } else {
88+ // 初回アクセス時は基本コースのみ読み込み
89+ await this . loadCourseChallenge ( 'sql-basics' , challengeFiles [ 'sql-basics' ] ) ;
90+ }
91+ }
92+
93+ /**
94+ * 特定コースのチャレンジデータを読み込み
95+ */
96+ async loadCourseChallenge ( courseId , filePath ) {
97+ // 既に読み込み済みの場合はスキップ
98+ if ( this . challengeData [ courseId ] ) {
99+ return this . challengeData [ courseId ] ;
100+ }
101+
102+ try {
103+ const response = await fetch ( filePath ) ;
104+ if ( response . ok ) {
105+ this . challengeData [ courseId ] = await response . json ( ) ;
106+ console . log ( `チャレンジデータを読み込みました: ${ courseId } ` ) ;
107+ } else {
108+ console . warn ( `チャレンジファイルが見つかりません: ${ filePath } ` ) ;
109+ this . challengeData [ courseId ] = [ ] ;
110+ }
111+ } catch ( error ) {
112+ console . error ( `チャレンジデータ読み込みエラー (${ courseId } ):` , error ) ;
113+
114+ // ErrorHandlerを使用してチャレンジデータエラーを処理
115+ if ( window . errorHandler ) {
116+ const result = await window . errorHandler . handleError ( 'CHALLENGE_LOAD_ERROR' , error , {
117+ courseId : courseId ,
118+ challengeFile : filePath ,
119+ operation : 'loadCourseChallenge'
120+ } ) ;
92121
93- // ErrorHandlerを使用してチャレンジデータエラーを処理
94- if ( window . errorHandler ) {
95- const result = await window . errorHandler . handleError ( 'CHALLENGE_LOAD_ERROR' , error , {
96- courseId : courseId ,
97- challengeFile : filePath ,
98- operation : 'loadChallengeData'
99- } ) ;
100-
101- if ( result . success ) {
102- this . challengeData [ courseId ] = result . data ;
103- } else {
104- this . challengeData [ courseId ] = [ ] ;
105- }
122+ if ( result . success ) {
123+ this . challengeData [ courseId ] = result . data ;
106124 } else {
107125 this . challengeData [ courseId ] = [ ] ;
108126 }
127+ } else {
128+ this . challengeData [ courseId ] = [ ] ;
109129 }
110130 }
131+
132+ return this . challengeData [ courseId ] ;
133+ }
134+
135+ /**
136+ * 必要に応じてコースのチャレンジデータを遅延読み込み
137+ */
138+ async ensureCourseDataLoaded ( courseId ) {
139+ if ( ! this . challengeData [ courseId ] ) {
140+ const challengeFiles = {
141+ 'sql-basics' : 'slides/challenges.json' ,
142+ 'db-fundamentals' : 'slides/db-fundamentals-challenges.json' ,
143+ 'big-data-basics' : 'slides/big-data-basics-challenges.json'
144+ } ;
145+
146+ if ( challengeFiles [ courseId ] ) {
147+ await this . loadCourseChallenge ( courseId , challengeFiles [ courseId ] ) ;
148+ }
149+ }
150+ return this . challengeData [ courseId ] || [ ] ;
111151 }
112152
113153 /**
@@ -169,12 +209,15 @@ class CourseManager {
169209 /**
170210 * コースを選択
171211 */
172- selectCourse ( courseId ) {
212+ async selectCourse ( courseId ) {
173213 const course = this . getCourse ( courseId ) ;
174214 if ( ! course ) {
175215 throw new Error ( `コースが見つかりません: ${ courseId } ` ) ;
176216 }
177217
218+ // コースのチャレンジデータを遅延読み込み
219+ await this . ensureCourseDataLoaded ( courseId ) ;
220+
178221 this . currentCourse = course ;
179222 this . progressManager . saveSelectedCourse ( courseId ) ;
180223
0 commit comments