4343 .link-card : hover { border-color : var (--accent ); }
4444
4545 # exercise-select { align-self : start; }
46+
47+ .record-controls {
48+ display : flex;
49+ align-items : center;
50+ gap : 0.75rem ;
51+ flex-wrap : wrap;
52+ }
53+
54+ .record-actions {
55+ display : flex;
56+ gap : 0.5rem ;
57+ }
4658 </ style >
4759</ head >
4860< body >
@@ -56,12 +68,16 @@ <h1>Workout Exercise Records</h1>
5668 < main >
5769
5870 < section class ="card grid ">
59- < div class ="flex between center ">
60- < h2 > Exercises</ h2 >
61- < button id ="refresh-exercises "> Refresh list</ button >
71+ < h2 > Records</ h2 >
72+ < div class ="record-controls ">
73+ < select id ="exercise-select "> </ select >
74+ < div class ="record-actions ">
75+ < button id ="get-records "> Get records</ button >
76+ < button id ="refresh-exercises "> Refresh list</ button >
77+ </ div >
6278 </ div >
63- < select id ="exercise-select "> </ select >
6479 < div id ="load-status " class ="status "> </ div >
80+ < div id ="viewing-label " aria-live ="polite "> Viewing records:</ div >
6581 < table >
6682 < thead > < tr > < th > Weight</ th > < th > Reps</ th > </ tr > </ thead >
6783 < tbody id ="record-rows "> </ tbody >
@@ -100,6 +116,7 @@ <h2 style="margin: 0;">Workout tools</h2>
100116 const recordStatus = document . getElementById ( 'record-status' ) ;
101117 const recordWeight = document . getElementById ( 'record-weight' ) ;
102118 const recordReps = document . getElementById ( 'record-reps' ) ;
119+ const viewingLabel = document . getElementById ( 'viewing-label' ) ;
103120
104121 const STORAGE_KEYS = { base : 'workout-api-base' , token : 'workout-api-token' } ;
105122
@@ -139,20 +156,29 @@ <h2 style="margin: 0;">Workout tools</h2>
139156 data . exercises . forEach ( ( ex ) => {
140157 const option = document . createElement ( 'option' ) ;
141158 option . value = ex . name ;
142- option . textContent = `${ ex . display_name } (${ ex . name } )` ;
159+ option . textContent = ex . display_name ;
160+ option . dataset . displayName = ex . display_name ;
143161 exerciseSelect . appendChild ( option ) ;
144162 } ) ;
145163 loadStatus . textContent = '' ;
146- loadRecords ( ) ;
164+ updateViewingLabel ( '' ) ;
165+ recordRows . innerHTML = '' ;
147166 } catch ( error ) {
148167 loadStatus . textContent = error . message ;
149168 }
150169 }
151170
171+ function updateViewingLabel ( name ) {
172+ viewingLabel . textContent = name ? `Viewing ${ name } records:` : 'Viewing records:' ;
173+ }
174+
152175 async function loadRecords ( ) {
153- const name = exerciseSelect . value ;
154- if ( ! name ) return ;
155- loadStatus . textContent = `Loading records for ${ name } ...` ;
176+ const selected = exerciseSelect . selectedOptions [ 0 ] ;
177+ if ( ! selected ) return ;
178+ const displayName = selected . dataset . displayName || selected . textContent ;
179+ const name = selected . value ;
180+ updateViewingLabel ( displayName ) ;
181+ loadStatus . textContent = `Loading records for ${ displayName } ...` ;
156182 recordRows . innerHTML = '' ;
157183 try {
158184 const data = await apiFetch ( `/exercises/${ encodeURIComponent ( name ) } /records` ) ;
@@ -186,11 +212,16 @@ <h2 style="margin: 0;">Workout tools</h2>
186212 }
187213
188214 document . getElementById ( 'refresh-exercises' ) . addEventListener ( 'click' , loadExercises ) ;
189- exerciseSelect . addEventListener ( 'change ' , ( ) => {
215+ document . getElementById ( 'get-records' ) . addEventListener ( 'click ' , ( ) => {
190216 clearRecordInputs ( ) ;
191217 recordStatus . textContent = '' ;
192218 loadRecords ( ) ;
193219 } ) ;
220+ exerciseSelect . addEventListener ( 'change' , ( ) => {
221+ clearRecordInputs ( ) ;
222+ recordStatus . textContent = '' ;
223+ loadStatus . textContent = '' ;
224+ } ) ;
194225
195226 document . getElementById ( 'record-form' ) . addEventListener ( 'submit' , async ( event ) => {
196227 event . preventDefault ( ) ;
0 commit comments