@@ -122,29 +122,45 @@ function scrollFocusedSectionIntoView( focusedSectionId ) {
122
122
function Root ( ) {
123
123
const [ focusedSection , setFocusedSection ] = useState ( global . location . hash . replace ( / ^ # / , '' ) ) ;
124
124
125
- const { didSaveOptions, fetchingOptions, saveOptions } = useContext ( Options ) ;
125
+ const { didSaveOptions, fetchingOptions, hasOptionsChanges , saveOptions } = useContext ( Options ) ;
126
126
const { error } = useContext ( ErrorContext ) ;
127
127
const { downloadingTheme } = useContext ( ReaderThemes ) ;
128
- const [ saved , setSaved ] = useState ( false ) ;
128
+ const [ savedNoticeClass , setSavedNoticeClass ] = useState ( '' ) ;
129
129
130
130
/**
131
- * Shows a saved notice on success .
131
+ * Show the success notice after options have saved .
132
132
*/
133
133
useEffect ( ( ) => {
134
- if ( true === didSaveOptions && ! downloadingTheme ) {
135
- setSaved ( true ) ;
134
+ if ( didSaveOptions && ! downloadingTheme ) {
135
+ setSavedNoticeClass ( 'visible' ) ;
136
+ }
137
+ } , [ didSaveOptions , downloadingTheme ] ) ;
138
+
139
+ /**
140
+ * If the success notice is showing and updates have been made, hide the notice.
141
+ */
142
+ useEffect ( ( ) => {
143
+ if ( 'visible' === savedNoticeClass && hasOptionsChanges ) {
144
+ setSavedNoticeClass ( 'dismissed' ) ;
145
+ }
146
+ } , [ savedNoticeClass , hasOptionsChanges ] ) ;
136
147
137
- const timeout = setTimeout ( ( ) => [
138
- setSaved ( false ) ,
139
- ] , 9000 ) ;
148
+ /**
149
+ * Hide the success notice after several seconds.
150
+ */
151
+ useEffect ( ( ) => {
152
+ if ( 'visible' === savedNoticeClass ) {
153
+ const timeout = setTimeout ( ( ) => {
154
+ setSavedNoticeClass ( 'dismissed' ) ;
155
+ } , 9000 ) ;
140
156
141
157
return ( ) => {
142
158
clearTimeout ( timeout ) ;
143
159
} ;
144
160
}
145
161
146
162
return ( ) => undefined ;
147
- } , [ didSaveOptions , downloadingTheme ] ) ;
163
+ } , [ savedNoticeClass ] ) ;
148
164
149
165
/**
150
166
* Scroll to the focused element on load or when it changes.
@@ -237,13 +253,15 @@ function Root() {
237
253
</ form >
238
254
< UnsavedChangesWarning excludeUserContext = { true } />
239
255
{ error && < ErrorNotice errorMessage = { error . message || __ ( 'An error occurred. You might be offline or logged out.' , 'amp' ) } /> }
240
- { saved && (
241
- < AMPNotice className = { `amp-save-success-notice` } type = { NOTICE_TYPE_SUCCESS } >
242
- < p >
243
- { __ ( 'Settings saved' , 'amp' ) }
244
- </ p >
245
- </ AMPNotice >
246
- ) }
256
+ < AMPNotice
257
+ className = { `amp-save-success-notice ${ savedNoticeClass } ` }
258
+ type = { NOTICE_TYPE_SUCCESS }
259
+ aria-hidden = { 'visible' !== savedNoticeClass }
260
+ >
261
+ < p >
262
+ { __ ( 'Settings saved' , 'amp' ) }
263
+ </ p >
264
+ </ AMPNotice >
247
265
</ >
248
266
) ;
249
267
}
0 commit comments