@@ -17,7 +17,9 @@ const LOCATE_ICON = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="
1717class Workout {
1818 id = ( Date . now ( ) + '' ) . slice ( - 10 ) ;
1919 date = new Date ( ) ;
20- workoutDate ;
20+ formattedDate ;
21+ cardTitle ;
22+ popupTitle ;
2123 clicks = 0 ;
2224 /**
2325 * @param {number } distance
@@ -28,7 +30,11 @@ class Workout {
2830 this . distance = distance ;
2931 this . duration = duration ;
3032 this . coords = coords ;
33+ this . calcDate ( ) ;
34+ this . setPopupTitle ( ) ;
35+ this . setCardTitle ( ) ;
3136 }
37+
3238 calcDate ( ) {
3339 const months = [
3440 'January' ,
@@ -44,7 +50,13 @@ class Workout {
4450 'November' ,
4551 'December' ,
4652 ] ;
47- this . workoutDate = `${ this . distance } km, ${ this . duration } m - ${ months [ this . date . getMonth ( ) ] } ${ this . date . getDate ( ) } , ${ this . date . getFullYear ( ) } ` ;
53+ this . formattedDate = `${ months [ this . date . getMonth ( ) ] } ${ this . date . getDate ( ) } , ${ this . date . getFullYear ( ) } ` ;
54+ }
55+ setPopupTitle ( ) {
56+ this . popupTitle = `${ this . type === 'running' ? '🏃♂️' : '🚴♀️' } ${ this . distance } km in ${ this . duration } min — ${ this . formattedDate } `
57+ }
58+ setCardTitle ( ) {
59+ this . cardTitle = `${ this . type === 'running' ? 'Running' : 'Cycling' } on ${ this . formattedDate } `
4860 }
4961 addClick ( ) {
5062 this . clicks ++ ;
@@ -57,7 +69,6 @@ class Running extends Workout {
5769 super ( distance , duration , coords ) ;
5870 this . cadence = cadence ;
5971 this . calcPace ( ) ;
60- this . calcDate ( ) ;
6172 }
6273
6374 calcPace ( ) {
@@ -71,7 +82,6 @@ class Cycling extends Workout {
7182 super ( distance , duration , coords ) ;
7283 this . elevationGain = elevationGain ;
7384 this . calcSpeed ( ) ;
74- this . calcDate ( ) ;
7585 }
7686
7787 calcSpeed ( ) {
@@ -268,16 +278,14 @@ class App {
268278 . addTo ( this . #map)
269279 . bindPopup (
270280 L . popup ( {
271- maxWidth : 250 ,
281+ maxWidth : 300 ,
272282 minWidth : 100 ,
273283 autoClose : false ,
274284 closeOnClick : false ,
275285 className : `${ workout . type } -popup` ,
276286 } )
277287 )
278- . setPopupContent (
279- `${ workout . type === 'running' ? '🏃♂️' : '🚴♀️' } ${ workout . workoutDate } `
280- )
288+ . setPopupContent ( workout . popupTitle )
281289 . openPopup ( ) ;
282290 }
283291
@@ -295,16 +303,14 @@ class App {
295303 className : `${ workout . type } -popup` ,
296304 } )
297305 )
298- . setPopupContent (
299- `${ workout . type === 'running' ? '🏃♂️' : '🚴♀️' } ${ workout . workoutDate } `
300- )
306+ . setPopupContent ( workout . popupTitle )
301307 . openPopup ( ) ;
302308 }
303309
304310 _renderWorkout ( workout ) {
305311 let html = `
306312 <li class="workout workout--${ workout . type } " data-id="${ workout . id } ">
307- <h2 class="workout__title">${ workout . workoutDate } </h2>
313+ <h2 class="workout__title">${ workout . cardTitle } </h2>
308314 <div class="workout__details">
309315 <span class="workout__icon">${ workout . type === 'running' ? '🏃♂️' : '🚴♀️'
310316 } </span>
0 commit comments