142142 font-weight : 600 ;
143143 margin-bottom : 0.25rem ;
144144 }
145+
146+ .records-context {
147+ margin : 0 ;
148+ font-weight : 600 ;
149+ }
145150 </ style >
146151</ head >
147152< body >
@@ -173,13 +178,15 @@ <h2>Records</h2>
173178 < button id ="refresh-exercises "> Refresh list</ button >
174179 </ div >
175180 </ div >
181+ < p id ="records-context " class ="status-text records-context "> No exercise selected.</ p >
176182 < div class ="record-table-container ">
177183 < div id ="load-status " class ="status "> </ div >
178184 < table class ="record-table ">
179185 < caption id ="records-caption " aria-live ="polite "> Select an exercise to view records</ caption >
180186 < thead > < tr > < th > Weight</ th > < th > Reps</ th > </ tr > </ thead >
181187 < tbody id ="record-rows "> </ tbody >
182188 </ table >
189+ < p id ="no-record-note " class ="status-text " aria-live ="polite "> </ p >
183190 </ div >
184191 </ section >
185192
@@ -218,6 +225,8 @@ <h2 style="margin: 0;">Workout tools</h2>
218225 const recordWeight = document . getElementById ( 'record-weight' ) ;
219226 const recordReps = document . getElementById ( 'record-reps' ) ;
220227 const recordsCaption = document . getElementById ( 'records-caption' ) ;
228+ const recordsContext = document . getElementById ( 'records-context' ) ;
229+ const noRecordNote = document . getElementById ( 'no-record-note' ) ;
221230
222231 const STORAGE_KEYS = { base : 'workout-api-base' , token : 'workout-api-token' } ;
223232
@@ -314,9 +323,13 @@ <h2 style="margin: 0;">Workout tools</h2>
314323 function updateRecordsCaption ( name , hasRecords ) {
315324 if ( ! name ) {
316325 recordsCaption . textContent = 'Select an exercise to view records' ;
326+ recordsContext . textContent = 'No exercise selected.' ;
327+ noRecordNote . textContent = '' ;
317328 return ;
318329 }
319330
331+ recordsContext . textContent = `Showing records for: ${ name } ` ;
332+
320333 recordsCaption . textContent = hasRecords === false
321334 ? `No ${ name } records`
322335 : `${ name } records` ;
@@ -333,6 +346,7 @@ <h2 style="margin: 0;">Workout tools</h2>
333346 updateRecordsCaption ( displayName ) ;
334347 loadStatus . textContent = `Loading records for ${ displayName } ...` ;
335348 recordRows . innerHTML = '' ;
349+ noRecordNote . textContent = '' ;
336350 try {
337351 const data = await apiFetch ( `/exercises/${ encodeURIComponent ( name ) } /records` ) ;
338352 ( data . records || [ ] ) . forEach ( ( rec ) => {
@@ -344,11 +358,13 @@ <h2 style="margin: 0;">Workout tools</h2>
344358 const row = document . createElement ( 'tr' ) ;
345359 row . innerHTML = '<td colspan="2">No personal bests yet.</td>' ;
346360 recordRows . appendChild ( row ) ;
361+ noRecordNote . textContent = `${ displayName } has no records yet.` ;
347362 }
348363 updateRecordsCaption ( displayName , data . records && data . records . length > 0 ) ;
349364 loadStatus . textContent = '' ;
350365 } catch ( error ) {
351366 loadStatus . textContent = error . message ;
367+ noRecordNote . textContent = '' ;
352368 }
353369 }
354370
@@ -374,17 +390,23 @@ <h2 style="margin: 0;">Workout tools</h2>
374390 exerciseSelect . addEventListener ( 'input' , ( ) => {
375391 clearRecordInputs ( ) ;
376392 recordStatus . textContent = '' ;
377- loadStatus . textContent = '' ;
378- updateRecordsCaption ( '' ) ;
379- recordRows . innerHTML = '' ;
380- } ) ;
393+ if ( ! getSelectedExercise ( ) ) {
394+ loadStatus . textContent = '' ;
395+ updateRecordsCaption ( '' ) ;
396+ recordRows . innerHTML = '' ;
397+ return ;
398+ }
381399
400+ loadRecords ( ) ;
401+ } ) ;
382402 exerciseBrowseSelect . addEventListener ( 'change' , ( event ) => {
383403 const selectedOption = event . target . selectedOptions [ 0 ] ;
384404 if ( ! selectedOption ) return ;
385405 const value = selectedOption . value || selectedOption . textContent ;
386406 exerciseSelect . value = value ;
387- exerciseSelect . dispatchEvent ( new Event ( 'input' , { bubbles : true } ) ) ;
407+ clearRecordInputs ( ) ;
408+ recordStatus . textContent = '' ;
409+ loadRecords ( ) ;
388410 const details = exerciseBrowseSelect . closest ( 'details' ) ;
389411 if ( details ) details . open = false ;
390412 } ) ;
0 commit comments