@@ -12,10 +12,11 @@ import {
1212import { models } from '@wordpress/api'
1313
1414let isPolling = false
15+ let cimoData = { status : cimo ?. status , action : cimo ?. action }
1516
1617const CimoDownloadNotice = props => {
1718 const { inMediaLibrary = false } = props
18- const [ data , setData ] = useState ( { status : cimo ?. status , action : cimo ?. action } )
19+ const [ data , setData ] = useState ( cimoData )
1920 const pollCountRef = useRef ( 0 )
2021
2122 const onDismiss = ( ) => {
@@ -71,22 +72,20 @@ const CimoDownloadNotice = props => {
7172
7273 const _data = res . data
7374
74- if ( data . status !== _data . status ) {
75- setData ( _data )
75+ // Stop polling if it has reached 3 attempts, or plugin status indicates installation/activation is complete
76+ if ( pollOnce || pollCountRef . current >= 3 ||
77+ ( action === 'install' && ( _data . status === 'installed' || _data . status === 'activated' ) ) ||
78+ ( action === 'activate' && _data . status === 'activated' )
79+ ) {
80+ cimoData = _data
81+ setData ( cimoData )
7682
7783 // Update the global stackable.cimo status/action variables
7884 // so new image block selections reflect the latest Cimo installation state
7985 if ( typeof window !== 'undefined' && window . stackable ?. cimo ) {
8086 window . stackable . cimo . status = _data . status
8187 window . stackable . cimo . action = _data . action
8288 }
83- }
84-
85- // Stop polling if it has reached 3 attempts, or plugin status indicates installation/activation is complete
86- if ( pollOnce || pollCountRef . current >= 3 ||
87- ( action === 'install' && ( _data . status === 'installed' || _data . status === 'activated' ) ) ||
88- ( action === 'activate' && _data . status === 'activated' )
89- ) {
9089 return
9190 }
9291
@@ -117,16 +116,15 @@ const CimoDownloadNotice = props => {
117116
118117 this . on ( 'close' , ( ) => {
119118 pollCountRef . current = 0
120- if ( data . status === 'activated' ) {
121- return
119+ const action = ( cimoData . status === 'installing' ) ? 'install'
120+ : ( cimoData . status === 'activating' ) ? 'activate' : false
121+
122+ if ( action ) {
123+ setData ( cimoData )
124+ setTimeout ( ( ) => {
125+ pollStatus ( action , null )
126+ } , 1000 )
122127 }
123-
124- if ( data . status === 'not_installed' ) {
125- pollStatus ( 'install' , null , true )
126- return
127- }
128-
129- pollStatus ( 'activate' , null , true )
130128 } )
131129 } ,
132130 } )
@@ -137,12 +135,14 @@ const CimoDownloadNotice = props => {
137135 pollCountRef . current = 0
138136
139137 if ( data . status === 'not_installed' ) {
140- setData ( { status : 'installing' , action : '' } )
138+ cimoData = { status : 'installing' , action : '' }
139+ setData ( cimoData )
141140 pollStatus ( 'install' , e . currentTarget . href )
142141 return
143142 }
144143
145- setData ( { status : 'activating' , action : '' } )
144+ cimoData = { status : 'activating' , action : '' }
145+ setData ( cimoData )
146146 pollStatus ( 'activate' , e . currentTarget . href )
147147 }
148148
0 commit comments