1
1
import cx from 'classnames' ;
2
2
import React , { Component , PropTypes } from 'react' ;
3
3
import Dialog from 'material-ui/Dialog' ;
4
+ import uniqueId from 'lodash/uniqueId' ;
4
5
5
6
import ArtistIcon from 'material-ui/svg-icons/hardware/headset' ;
6
7
import TitleIcon from 'material-ui/svg-icons/image/music-note' ;
@@ -17,7 +18,7 @@ import TextField from '../../Form/TextField';
17
18
// naive HH:mm:ss → seconds
18
19
const parseDuration = str => str . split ( ':' )
19
20
. map ( part => parseInt ( part . trim ( ) , 10 ) )
20
- . reduce ( ( duration , part ) => duration * 60 + part , 0 ) ;
21
+ . reduce ( ( duration , part ) => ( duration * 60 ) + part , 0 ) ;
21
22
22
23
export default class EditMediaDialog extends Component {
23
24
static propTypes = {
@@ -36,11 +37,14 @@ export default class EditMediaDialog extends Component {
36
37
errors : null
37
38
} ;
38
39
40
+ labelStart = uniqueId ( 'editmedia' ) ;
41
+ labelEnd = uniqueId ( 'editmedia' ) ;
42
+
39
43
handleSubmit = e => {
40
44
e . preventDefault ( ) ;
41
45
42
46
const { media, onEditedMedia, onCloseDialog } = this . props ;
43
- const { artist, title, start, end } = this . refs ;
47
+ const { artist, title, start, end } = this ;
44
48
45
49
const startSeconds = parseDuration ( start . value ) ;
46
50
const endSeconds = parseDuration ( end . value ) ;
@@ -71,6 +75,22 @@ export default class EditMediaDialog extends Component {
71
75
onCloseDialog ( ) ;
72
76
} ;
73
77
78
+ refArtist = artist => {
79
+ this . artist = artist ;
80
+ } ;
81
+
82
+ refTitle = title => {
83
+ this . title = title ;
84
+ } ;
85
+
86
+ refStart = start => {
87
+ this . start = start ;
88
+ } ;
89
+
90
+ refEnd = end => {
91
+ this . end = end ;
92
+ } ;
93
+
74
94
render ( ) {
75
95
const {
76
96
open,
@@ -89,7 +109,7 @@ export default class EditMediaDialog extends Component {
89
109
if ( open ) {
90
110
const artistInput = (
91
111
< TextField
92
- ref = "artist"
112
+ ref = { this . refArtist }
93
113
className = "EditMediaDialogGroup-field"
94
114
placeholder = "Artist"
95
115
defaultValue = { media . artist }
@@ -99,11 +119,11 @@ export default class EditMediaDialog extends Component {
99
119
/>
100
120
) ;
101
121
const artistTitleLabel = (
102
- < label className = "EditMediaDialogGroup-label" > –</ label >
122
+ < div className = "EditMediaDialogGroup-label" > –</ div >
103
123
) ;
104
124
const titleInput = (
105
125
< TextField
106
- ref = "title"
126
+ ref = { this . refTitle }
107
127
className = "EditMediaDialogGroup-field"
108
128
placeholder = "Title"
109
129
defaultValue = { media . title }
@@ -113,11 +133,12 @@ export default class EditMediaDialog extends Component {
113
133
) ;
114
134
115
135
const fromLabel = (
116
- < label className = "EditMediaDialogGroup-label" > Play from:</ label >
136
+ < label htmlFor = { this . labelStart } className = "EditMediaDialogGroup-label" > Play from:</ label >
117
137
) ;
118
138
const fromInput = (
119
139
< TextField
120
- ref = "start"
140
+ ref = { this . refStart }
141
+ id = { this . labelStart }
121
142
className = "EditMediaDialogGroup-field"
122
143
placeholder = "0:00"
123
144
defaultValue = { formatDuration ( media . start ) }
@@ -126,11 +147,12 @@ export default class EditMediaDialog extends Component {
126
147
/>
127
148
) ;
128
149
const toLabel = (
129
- < label className = "EditMediaDialogGroup-label" > to:</ label >
150
+ < label htmlFor = { this . labelEnd } className = "EditMediaDialogGroup-label" > to:</ label >
130
151
) ;
131
152
const toInput = (
132
153
< TextField
133
- ref = "end"
154
+ ref = { this . refEnd }
155
+ id = { this . labelEnd }
134
156
className = "EditMediaDialogGroup-field"
135
157
placeholder = { formatDuration ( media . duration ) }
136
158
defaultValue = { formatDuration ( media . end ) }
0 commit comments