@@ -37,6 +37,7 @@ export default class DaTitle extends LitElement {
3737 collabUsers : { attribute : false } ,
3838 previewPrefix : { attribute : false } ,
3939 livePrefix : { attribute : false } ,
40+ hasChanges : { attribute : false } ,
4041 _actionsVis : { state : true } ,
4142 _status : { state : true } ,
4243 _fixedActions : { state : true } ,
@@ -47,7 +48,13 @@ export default class DaTitle extends LitElement {
4748 super . connectedCallback ( ) ;
4849 this . shadowRoot . adoptedStyleSheets = [ sheet ] ;
4950 this . _actionsVis = [ ] ;
51+ this . hasChanges = false ;
5052 inlinesvg ( { parent : this . shadowRoot , paths : ICONS } ) ;
53+
54+ if ( this . _isConfigView ) {
55+ this . _actionsVis = [ 'save' ] ;
56+ }
57+
5158 if ( this . details . view === 'sheet' ) {
5259 this . collabStatus = window . navigator . onLine
5360 ? 'connected'
@@ -68,6 +75,7 @@ export default class DaTitle extends LitElement {
6875 }
6976
7077 handleError ( json , action , icon ) {
78+ // eslint-disable-next-line no-console
7179 console . log ( 'handleError' , json , action , icon ) ;
7280 this . _status = { ...json . error , action } ;
7381 icon . classList . remove ( 'is-sending' ) ;
@@ -93,8 +101,14 @@ export default class DaTitle extends LitElement {
93101 async handleAction ( action ) {
94102 this . toggleActions ( ) ;
95103 this . _status = null ;
96- const sendBtn = this . shadowRoot . querySelector ( '.da-title-action-send-icon' ) ;
97- sendBtn . classList . add ( 'is-sending' ) ;
104+
105+ const sendBtn = this . shadowRoot . querySelector (
106+ this . _isConfigView ? '.da-title-action' : '.da-title-action-send-icon' ,
107+ ) ;
108+
109+ if ( sendBtn ) {
110+ sendBtn . classList . add ( 'is-sending' ) ;
111+ }
98112
99113 const { hash } = window . location ;
100114 const pathname = hash . replace ( '#' , '' ) ;
@@ -104,13 +118,21 @@ export default class DaTitle extends LitElement {
104118 const dasSave = await saveToDa ( pathname , this . sheet ) ;
105119 if ( ! dasSave . ok ) return ;
106120 }
107- if ( this . details . view === 'config' ) {
121+
122+ if ( this . _isConfigView ) {
108123 const daConfigResp = await saveDaConfig ( pathname , this . sheet ) ;
124+
125+ if ( sendBtn ) {
126+ sendBtn . classList . remove ( 'is-sending' ) ;
127+ }
128+
109129 if ( ! daConfigResp . ok ) {
110130 // eslint-disable-next-line no-console
111131 console . log ( 'Saving configuration failed because:' , daConfigResp . status , await daConfigResp . text ( ) ) ;
112- return ;
132+ } else {
133+ this . hasChanges = false ;
113134 }
135+ return ;
114136 }
115137 if ( action === 'preview' || action === 'publish' ) {
116138 const cdn = await getCdnConfig ( pathname ) ;
@@ -141,7 +163,7 @@ export default class DaTitle extends LitElement {
141163 window . open ( `${ toOpenInAem } ?nocache=${ Date . now ( ) } ` , toOpenInAem ) ;
142164 }
143165 if ( this . details . view === 'edit' && action === 'publish' ) saveDaVersion ( pathname ) ;
144- sendBtn . classList . remove ( 'is-sending' ) ;
166+ if ( sendBtn ) sendBtn . classList . remove ( 'is-sending' ) ;
145167 }
146168
147169 async handleRoleRequest ( ) {
@@ -189,15 +211,14 @@ export default class DaTitle extends LitElement {
189211 }
190212
191213 async toggleActions ( ) {
192- // toggle off if already on
193- if ( this . _actionsVis . length > 0 ) {
194- this . _actionsVis = [ ] ;
214+ // Config view doesn't toggle
215+ if ( this . _isConfigView ) {
195216 return ;
196217 }
197218
198- // toggle on for config
199- if ( this . details . view === 'config' ) {
200- this . _actionsVis = [ 'save' ] ;
219+ // toggle off if already on
220+ if ( this . _actionsVis . length > 0 ) {
221+ this . _actionsVis = [ ] ;
201222 return ;
202223 }
203224
@@ -217,12 +238,17 @@ export default class DaTitle extends LitElement {
217238 return ! this . permissions . some ( ( permission ) => permission === 'write' ) ;
218239 }
219240
241+ get _isConfigView ( ) {
242+ return this . details . view === 'config' ;
243+ }
244+
220245 renderActions ( ) {
221246 return html `${ this . _actionsVis . map ( ( action ) => html `
222247 < button
223248 @click =${ ( ) => this . handleAction ( action ) }
224- class ="con-button blue da-title-action"
225- aria-label="Send">
249+ class ="con-button da-title-action ${ this . _isConfigView && ! this . hasChanges ? '' : 'blue' } "
250+ aria-label="${ action } "
251+ ?disabled=${ this . _isConfigView && ! this . hasChanges } >
226252 ${ action . charAt ( 0 ) . toUpperCase ( ) + action . slice ( 1 ) }
227253 </ button >
228254 ` ) } `;
@@ -290,14 +316,16 @@ export default class DaTitle extends LitElement {
290316 < div class ="da-title-collab-actions-wrapper ">
291317 ${ this . collabStatus ? this . renderCollab ( ) : nothing }
292318 ${ this . _status ? this . renderError ( ) : nothing }
293- < div class ="da-title-actions ${ this . _fixedActions ? 'is-fixed' : '' } ${ this . _actionsVis . length > 0 ? 'is-open' : '' } ">
319+ < div class ="da-title-actions ${ this . _fixedActions ? 'is-fixed' : '' } ${ ! this . _isConfigView && this . _actionsVis . length > 0 ? 'is-open' : '' } ${ this . _isConfigView ? 'config ' : '' } ">
294320 ${ this . renderActions ( ) }
295- < button
296- @click =${ this . toggleActions }
297- class ="con-button blue da-title-action-send"
298- aria-label="Send">
299- < span class ="da-title-action-send-icon "> </ span >
300- </ button >
321+ ${ this . _isConfigView ? nothing : html `
322+ < button
323+ @click =${ this . toggleActions }
324+ class ="con-button blue da-title-action-send"
325+ aria-label="Send">
326+ < span class ="da-title-action-send-icon "> </ span >
327+ </ button >
328+ ` }
301329 </ div >
302330 </ div >
303331 </ div >
0 commit comments