@@ -224,7 +224,30 @@ <h2>Generated Routine</h2>
224224 let selectedCourses = [ ] ;
225225 let sortAscending = true ;
226226
227- // Initialization function to wire-up all event listeners
227+ // Load any persisted data from localStorage
228+ function loadDataFromLocalStorage ( ) {
229+ const storedCourses = localStorage . getItem ( 'courses' ) ;
230+ const storedGrouped = localStorage . getItem ( 'groupedCourses' ) ;
231+ if ( storedCourses && storedGrouped ) {
232+ courses = JSON . parse ( storedCourses ) ;
233+ groupedCourses = JSON . parse ( storedGrouped ) ;
234+ // Enable controls for filtering and searching
235+ document . getElementById ( 'searchInput' ) . disabled = false ;
236+ document . getElementById ( 'deptFilter' ) . disabled = false ;
237+ document . getElementById ( 'classTypeFilter' ) . disabled = false ;
238+ document . getElementById ( 'clearAll' ) . disabled = false ;
239+ // Rebuild the department filter options from available courses
240+ const depts = new Set ( ) ;
241+ Object . values ( courses ) . forEach ( c => {
242+ if ( c . dept ) depts . add ( c . dept ) ;
243+ } ) ;
244+ document . getElementById ( 'deptFilter' ) . innerHTML = [ '<option value="">All Departments</option>' ]
245+ . concat ( Array . from ( depts ) . map ( d => `<option>${ d } </option>` ) ) . join ( '' ) ;
246+ renderCourseList ( ) ;
247+ }
248+ }
249+
250+ // Initialization function to wire-up all event listeners and load persisted data
228251 function init ( ) {
229252 document . getElementById ( 'dropZone' ) . addEventListener ( 'click' , ( ) => {
230253 document . getElementById ( 'fileInput' ) . click ( ) ;
@@ -241,6 +264,8 @@ <h2>Generated Routine</h2>
241264 sortSelectedCourses ( 'code' , sortAscending ) ;
242265 renderSelectedTable ( ) ;
243266 } ) ;
267+ // Load persisted data if it exists
268+ loadDataFromLocalStorage ( ) ;
244269 }
245270
246271 // Notification helper
@@ -252,9 +277,11 @@ <h2>Generated Routine</h2>
252277 setTimeout ( ( ) => el . style . display = 'none' , 3000 ) ;
253278 }
254279
255- // Clear all courses and reload the page
280+ // Clear all courses: clear persistent storage and reload the page
256281 function clearAll ( ) {
257282 if ( confirm ( "Are you sure you want to clear all?" ) ) {
283+ localStorage . removeItem ( 'courses' ) ;
284+ localStorage . removeItem ( 'groupedCourses' ) ;
258285 location . reload ( ) ;
259286 }
260287 }
@@ -356,6 +383,10 @@ <h2>Generated Routine</h2>
356383 groupedCourses [ info . title ] . push ( info ) ;
357384 } ) ;
358385
386+ // Persist the data in localStorage
387+ localStorage . setItem ( 'courses' , JSON . stringify ( courses ) ) ;
388+ localStorage . setItem ( 'groupedCourses' , JSON . stringify ( groupedCourses ) ) ;
389+
359390 // Initialize dropdown filters and enable controls
360391 document . getElementById ( 'deptFilter' ) . innerHTML = [ '<option value="">All Departments</option>' ]
361392 . concat ( Array . from ( depts ) . map ( d => `<option>${ d } </option>` ) ) . join ( '' ) ;
0 commit comments