@@ -28,6 +28,12 @@ const TagsBlock = React.createClass({
2828 Reflux . connect ( FilterStore , 'filterStore' )
2929 ] ,
3030
31+ getInitialState ( ) {
32+ return ( {
33+ tagEditingKey : ''
34+ } ) ;
35+ } ,
36+
3137 componentDidMount ( ) {
3238 const userID = this . props . openUser . id ;
3339 const query = this . props . query ;
@@ -73,18 +79,40 @@ const TagsBlock = React.createClass({
7379 //
7480 const openUserName = this . props . openUser . login ;
7581 const tagKey = tag . key ;
76- const isRemoving = event && ~ event . target . className . indexOf ( 'tag-remove-icon' ) ;
82+ const targetClassName = event . target . className ;
83+ const isRemoving = ~ targetClassName . indexOf ( 'tag-remove-icon' ) ;
84+ const isEditing = ~ targetClassName . indexOf ( 'tag-edit-icon' ) ;
85+ if ( ~ targetClassName . indexOf ( 'tag-edit-input' ) ) {
86+ return ;
87+ }
7788 if ( isRemoving ) {
7889 this . props . setFirebaseTags ( tagKey ) ;
7990 activeTags = _ . difference ( activeTags , [ tagKey ] ) ;
8091 }
92+ else if ( isEditing ) {
93+ this . setState ( {
94+ tagEditingKey : tag . key
95+ } ) ;
96+ }
8197 else {
8298 activeTags = _ . xor ( activeTags , [ tagKey ] ) ;
8399 }
84100 //
85- const tagReposIds = this . getTagReposIds ( this . props . tags , activeTags ) ;
86- FilterActions . setTagsReposIds ( tagReposIds ) ;
87- FilterActions . setTags ( activeTags ) ;
101+ if ( ! isEditing ) {
102+ const tagReposIds = this . getTagReposIds ( this . props . tags , activeTags ) ;
103+ FilterActions . setTagsReposIds ( tagReposIds ) ;
104+ FilterActions . setTags ( activeTags ) ;
105+ }
106+ } ,
107+
108+ handleKeyUp ( e ) {
109+ if ( e . keyCode == 13 ) {
110+ this . submitTagEdit ( ) ;
111+ }
112+ } ,
113+
114+ submitTagEdit ( ) {
115+ this . props . editTag ( this . state . tagEditingKey , this . refs . inputTagEdit . getValue ( ) . trim ( ) ) ;
88116 } ,
89117
90118 render ( ) {
@@ -120,19 +148,41 @@ const TagsBlock = React.createClass({
120148 let activeClass = filterStore && _ . includes ( filterStore . tags , tag . key ) ?
121149 ' active' :
122150 '' ;
151+ let editingClass = ( this . state . tagEditingKey === tag . key ) ?
152+ ' active editing-tag' :
153+ '' ;
123154 //
124155 return (
125156 < span
126- className = { 'tag' + activeClass }
157+ className = { 'tag' + activeClass + editingClass }
127158 key = { 'tag-' + tag . key }
128159 onClick = { ( e ) => this . filterReposByTags ( e , tag ) }
129160 >
130- { tag . key }
161+ { this . state . tagEditingKey !== tag . key ?
162+ tag . key :
163+ < Input
164+ type = "text"
165+ ref = "inputTagEdit"
166+ defaultValue = { tag . key }
167+ className = "tag-edit-input"
168+ onKeyUp = { ( e ) => this . handleKeyUp ( e ) }
169+ />
170+ }
131171 { isCurrentUser ?
132- < FontAwesome
133- className = "tag-remove-icon"
134- name = "times"
135- /> :
172+ [
173+ < FontAwesome
174+ key = "tag-remove-icon"
175+ className = "tag-icon tag-remove-icon"
176+ name = "times"
177+ title = "Remove tag"
178+ /> ,
179+ < FontAwesome
180+ key = "tag-edit-icon"
181+ className = "tag-icon tag-edit-icon"
182+ name = "pencil"
183+ title = "Edit tag"
184+ />
185+ ] :
136186 null
137187 }
138188 </ span >
0 commit comments