@@ -59,6 +59,22 @@ export class AlbumDetail extends LitElement {
59
59
padding-bottom: 1rem;
60
60
font-size: 1rem;
61
61
}
62
+
63
+ h6 {
64
+ margin: 0;
65
+ padding-bottom: 1rem;
66
+ font-size: 0.8rem;
67
+ color: var(--secondary-text-color);
68
+ }
69
+
70
+ div.track {
71
+ display: flex;
72
+ justify-content: space-between;
73
+ }
74
+
75
+ div.track > .duration {
76
+ color: var(--secondary-text-color);
77
+ }
62
78
` ;
63
79
64
80
constructor ( ) {
@@ -82,17 +98,47 @@ export class AlbumDetail extends LitElement {
82
98
? html `(${ this . album . releaseYear . value } )`
83
99
: nothing }
84
100
</ h5 >
101
+ < h6 > ${ this . _formatAlbumDuration ( ) } </ h6 >
85
102
</ div >
86
103
87
104
< div class ="track-list-container " slot ="right-column ">
88
105
< h2 > Tracks</ h2 >
89
106
< ol class ="track-list ">
90
- ${ map ( this . album . tracks , ( track ) => html `< li > ${ track . name } </ li > ` ) }
107
+ ${ map (
108
+ this . album . tracks ,
109
+ ( track ) =>
110
+ html `< div class ="track ">
111
+ < li > ${ track . name } </ li >
112
+ < span class ="duration "
113
+ > ${ this . _formatDuration ( track . durationInSeconds ) } </ span
114
+ >
115
+ </ div > ` ,
116
+ ) }
91
117
</ ol >
92
118
</ div >
93
119
</ two-column-layout >
94
120
` ;
95
121
}
122
+
123
+ private _formatDuration ( durationInSeconds : number ) : string {
124
+ if ( durationInSeconds === 0 ) return "" ;
125
+
126
+ const date = new Date ( 0 ) ;
127
+ date . setSeconds ( durationInSeconds ) ;
128
+ return date . toLocaleTimeString ( "en-US" , {
129
+ minute : "2-digit" ,
130
+ second : "2-digit" ,
131
+ } ) ;
132
+ }
133
+
134
+ private _formatAlbumDuration ( ) : string {
135
+ const durationInSeconds = this . album . tracks . reduce (
136
+ ( acc , track ) => acc + track . durationInSeconds ,
137
+ 0 ,
138
+ ) ;
139
+ const durationInMinutes = Math . floor ( durationInSeconds / 60 ) ;
140
+ return `${ durationInMinutes } min` ;
141
+ }
96
142
}
97
143
98
144
@customElement ( "album-detail-page" )
0 commit comments