@@ -27,25 +27,47 @@ let thePosts = null;
2727let callbackSetData = null ;
2828let callbackSetUnread = null ;
2929
30+ /**
31+ * Get the number of unread announcements, to display in the main menu
32+ *
33+ * @param {Function } setUnreadCount the callback function for setting the unread count
34+ */
3035async function getUnreadCount ( setUnreadCount ) {
31- callbackSetUnread = setUnreadCount ;
36+ if ( setUnreadCount ) {
37+ callbackSetUnread = setUnreadCount ;
38+ }
3239 await refresh ( callbackSetData ) ;
3340}
3441
42+ /**
43+ * Refresh the Announcements page and/or unread count
44+ *
45+ * @param {Function } viewCallbackSetData the callback function for the Announcements page, or null
46+ *
47+ * The callback function for setting the data may be null if the Announcements page isn't open and
48+ * we're only getting the number of unread announcements to display in the main header
49+ */
3550async function refresh ( viewCallbackSetData ) {
3651 if ( DISABLE_ANNOUNCEMENTS ) {
3752 return ;
3853 }
39- if ( schedule . tooSoon ( ) ) {
40- return ;
54+ if ( viewCallbackSetData ) {
55+ if ( ! callbackSetData ) {
56+ // The Announcements page was just opened, so re-fetch the data immediately regardless
57+ // of how recently it was fetched previously (for unread count)
58+ schedule . reset ( ) ;
59+ }
60+ callbackSetData = viewCallbackSetData ;
4161 }
4262 if ( ! cldrStatus . getSurveyUser ( ) ) {
4363 if ( viewCallbackSetData ) {
4464 viewCallbackSetData ( null ) ;
4565 }
4666 return ;
4767 }
48- callbackSetData = viewCallbackSetData ;
68+ if ( schedule . tooSoon ( ) ) {
69+ return ;
70+ }
4971 const url = cldrAjax . makeApiUrl ( "announce" , null ) ;
5072 schedule . setRequestTime ( ) ;
5173 return await cldrAjax
@@ -63,7 +85,7 @@ function setPosts(json) {
6385 callbackSetData ( thePosts ) ;
6486 }
6587 if ( callbackSetUnread ) {
66- let totalCount = thePosts . announcements ?. length || 0 ;
88+ const totalCount = thePosts . announcements ?. length || 0 ;
6789 let checkedCount = 0 ;
6890 for ( let announcement of thePosts . announcements ) {
6991 if ( announcement . checked ) {
@@ -85,6 +107,7 @@ function canChooseAllOrgs() {
85107}
86108
87109async function compose ( formState , viewCallbackComposeResult ) {
110+ schedule . reset ( ) ;
88111 const init = cldrAjax . makePostData ( formState ) ;
89112 const url = cldrAjax . makeApiUrl ( "announce" , null ) ;
90113 return await cldrAjax
0 commit comments