@@ -112,10 +112,11 @@ class Trello extends React.Component {
112112
113113
114114 try {
115- const currentLabels = ( await ( await this . fetch ( { path : `boards/${ boardId } /labels` , query : { fields : 'name' } } ) ) . json ( ) )
115+ const currentLabels = ( await ( await this . fetch ( { path : `boards/${ boardId } /labels` , query : { fields : 'name,color ' } } ) ) . json ( ) )
116116 const createLabelsPromices = TRELLO_LABELS . map ( l => this . createLabel ( boardId , l , currentLabels ) )
117+ const removeLabelPromices = COLORS . map ( l => this . removeLabel ( boardId , l , currentLabels ) )
117118
118- await Promise . all ( createLabelsPromices )
119+ await Promise . all ( [ ... createLabelsPromices , ... removeLabelPromices ] )
119120 this . setState ( {
120121 applying : false ,
121122 alert : { type : 'success' , message : 'Setup completed !' }
@@ -156,11 +157,15 @@ class Trello extends React.Component {
156157 } ) )
157158 }
158159
159- async removeLabel ( boardId , { name } ) {
160- await this . fetch (
161- `https://Trello.com/api/v4/boards/${ boardId } /labels?name=${ name } ` ,
162- 'DELETE'
163- ) ;
160+ async removeLabel ( boardId , { name } , currentLabels ) {
161+ const cl = currentLabels . filter ( cl => cl . color === name && cl . name === "" ) . pop ( ) ;
162+
163+ if ( ! cl ) {
164+ this . addApplyedLabel ( name ) ;
165+ return ;
166+ }
167+
168+ await this . fetch ( { path : `labels/${ cl . id } ` , method : 'DELETE' } ) ;
164169
165170 this . setState ( ( { applyedLabels } ) => ( {
166171 applyedLabels : [ ...applyedLabels , name ] ,
@@ -193,6 +198,7 @@ class Trello extends React.Component {
193198 selectedPreject = { selectedOption }
194199
195200 labelsToAdd = { TRELLO_LABELS }
201+ labelsToRemove = { COLORS }
196202
197203 onApply = { ( selected ) => this . handleApply ( selected ) }
198204
0 commit comments