@@ -66,28 +66,31 @@ $(function () {
6666
6767 } ) ;
6868
69- // Reload page periodically if the enableAutoReload checkbox is present and checked
70- const autoReloadSwitch = document . getElementById ( "enableAutoReload" ) ;
71- const timeSinceDisplay = document . getElementById ( "time-since-uploaded" ) ;
72- if ( autoReloadSwitch ) {
73- const autoReloadTime = 30000 ; // ms
74- let autoReloadTimeoutId ;
75- autoReloadSwitch . parentElement . classList . remove ( "d-none" ) ;
76- timeSinceDisplay . classList . remove ( "d-none" ) ;
77- autoReloadTimeoutId = setTimeout ( ( ) => location . reload ( ) , autoReloadTime ) ;
78- autoReloadSwitch . addEventListener ( "change" , ( e ) => {
79- if ( e . currentTarget . checked ) {
80- if ( ! autoReloadTimeoutId ) {
81- autoReloadTimeoutId = setTimeout ( ( ) => location . reload ( ) , autoReloadTime ) ;
82- timeSinceDisplay . classList . remove ( "d-none" ) ;
83- }
84- } else {
85- if ( autoReloadTimeoutId ) {
86- clearTimeout ( autoReloadTimeoutId ) ;
87- autoReloadTimeoutId = null ;
88- timeSinceDisplay . classList . add ( "d-none" ) ;
89- }
69+ // If draft is validating, poll until validation is complete, then reload the page
70+ const submissionValidatingAlert = document . getElementById ( 'submission-validating-alert' ) ;
71+ if ( submissionValidatingAlert ) {
72+ let statusPollTimer ;
73+ const statusUrl = submissionValidatingAlert . dataset [ 'submissionStatusUrl' ] ;
74+ let statusPollInterval = 2000 ; // ms
75+ const maxPollInterval = 32000 ; // ms
76+
77+ function checkStatus ( ) {
78+ if ( statusPollInterval < maxPollInterval ) {
79+ statusPollInterval *= 2 ;
9080 }
91- } ) ;
81+ const xhr = new XMLHttpRequest ( ) ;
82+ xhr . open ( "GET" , statusUrl , true ) ;
83+ xhr . onload = ( e ) => {
84+ if ( xhr . response && xhr . response . state !== 'validating' ) {
85+ location . reload ( ) ;
86+ } else {
87+ statusPollTimer = setTimeout ( checkStatus , statusPollInterval ) ;
88+ }
89+ } ;
90+ xhr . onerror = ( e ) => { statusPollTimer = setTimeout ( checkStatus , statusPollInterval ) ; } ;
91+ xhr . responseType = 'json' ;
92+ xhr . send ( '' ) ;
93+ }
94+ statusPollTimer = setTimeout ( checkStatus , statusPollInterval ) ;
9295 }
9396} ) ;
0 commit comments