Skip to content

Commit 7de0280

Browse files
committed
lazy load cimo notice, display notice in image control
1 parent 1427503 commit 7de0280

File tree

11 files changed

+432
-160
lines changed

11 files changed

+432
-160
lines changed

.config/webpack.config.dev.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ module.exports = [
178178
'frontend_block_horizontal_scroller': path.resolve( __dirname, '../src/block/horizontal-scroller/frontend-horizontal-scroller.js' ),
179179
'frontend_block_tabs': path.resolve( __dirname, '../src/block/tabs/frontend-tabs.js' ),
180180
'frontend_image_optimizer_polyfill': path.resolve( __dirname, '../src/block-components/image/image-optimizer-polyfill.js' ),
181-
'stk_cimo_notice': path.resolve( __dirname, '../src/compatibility/cimo/index.js' ),
182181
},
183182

184183
output: {

.config/webpack.config.prod.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ module.exports = [
163163
'frontend_block_horizontal_scroller': path.resolve( __dirname, '../src/block/horizontal-scroller/frontend-horizontal-scroller.js' ),
164164
'frontend_block_tabs': path.resolve( __dirname, '../src/block/tabs/frontend-tabs.js' ),
165165
'frontend_image_optimizer_polyfill': path.resolve( __dirname, '../src/block-components/image/image-optimizer-polyfill.js' ),
166-
'stk_cimo_notice': path.resolve( __dirname, '../src/compatibility/cimo/index.js' ),
167166
},
168167

169168
output: {

plugin.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ function is_frontend() {
288288
require_once( plugin_dir_path( __FILE__ ) . 'src/plugins/global-settings/block-styles/index.php' );
289289
require_once( plugin_dir_path( __FILE__ ) . 'src/css-optimize.php' );
290290
require_once( plugin_dir_path( __FILE__ ) . 'src/compatibility/index.php' );
291+
292+
// For cross-selling
293+
require_once( plugin_dir_path( __FILE__ ) . 'src/lazy-components/cimo/index.php' );
294+
291295
if ( ! is_admin() ) {
292296
require_once( plugin_dir_path( __FILE__ ) . 'src/lightbox/index.php' );
293297
require_once( plugin_dir_path( __FILE__ ) . 'src/block/accordion/index.php' );

src/compatibility/cimo/index.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/compatibility/cimo/index.php

Lines changed: 0 additions & 113 deletions
This file was deleted.

src/compatibility/index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@
99
require_once( plugin_dir_path( __FILE__ ) . './ewww.php' );
1010
require_once( plugin_dir_path( __FILE__ ) . './woocommerce.php' );
1111
require_once( plugin_dir_path( __FILE__ ) . './blocksy/index.php' );
12-
require_once( plugin_dir_path( __FILE__ ) . './cimo/index.php' );

src/components/image-control2/index.js

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Button from '../button'
1111
* External dependencies
1212
*/
1313
import classnames from 'classnames'
14-
import { i18n } from 'stackable'
14+
import { i18n, cimo } from 'stackable'
1515
import {
1616
useAttributeName, useBlockAttributesContext, useBlockSetAttributesContext,
1717
} from '~stackable/hooks'
@@ -20,8 +20,11 @@ import {
2020
* WordPress dependencies
2121
*/
2222
import { __ } from '@wordpress/i18n'
23-
import { Fragment, memo } from '@wordpress/element'
23+
import {
24+
Fragment, memo, useEffect, useState,
25+
} from '@wordpress/element'
2426
import { MediaUpload } from '@wordpress/block-editor'
27+
import { currentUserHasCapability } from '~stackable/util'
2528

2629
const ImageControl = memo( props => {
2730
const attrNameId = useAttributeName( `${ props.attribute }Id`, props.responsive, props.hover )
@@ -81,7 +84,37 @@ const ImageControl = memo( props => {
8184
} )
8285
}
8386

84-
return (
87+
const [ CimoDownloadNotice, setCimoDownloadNotice ] = useState( null )
88+
89+
useEffect( () => {
90+
// Skip displaying the Cimo notice if the plugin is already activated or the user has chosen to hide the notice
91+
if ( ! cimo || cimo.hideNotice || cimo.status === 'activated' ) {
92+
return
93+
}
94+
95+
const userCanInstall = currentUserHasCapability( 'install_plugins' )
96+
const userCanActivate = currentUserHasCapability( 'activate_plugins' )
97+
// Show the Cimo notice only if the user has permissions to install or activate plugins
98+
if ( ( cimo.status === 'not_installed' && userCanInstall ) || ( cimo.status === 'installed' && userCanActivate ) ) {
99+
const loadNotice = async () => {
100+
try {
101+
// Import the Cimo notice component with explicit chunk naming
102+
const { default: CimoNoticeComponent } = await import(
103+
/* webpackChunkName: "cimo-download-notice" */
104+
/* webpackMode: "lazy" */
105+
'../../lazy-components/cimo'
106+
)
107+
setCimoDownloadNotice( () => CimoNoticeComponent )
108+
} catch ( err ) {
109+
// eslint-disable-next-line no-console
110+
console.error( 'Failed to load Cimo download notice component:', err )
111+
}
112+
}
113+
loadNotice()
114+
}
115+
}, [] )
116+
117+
return ( <>
85118
<AdvancedControl
86119
{ ...controlProps }
87120
valueCheckAttribute={ props.attribute + 'Url' }
@@ -112,7 +145,7 @@ const ImageControl = memo( props => {
112145
/>
113146
) }
114147
{ type === 'image' && (
115-
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
148+
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
116149
<img
117150
className="ugb-image-preview"
118151
draggable="false"
@@ -172,6 +205,8 @@ const ImageControl = memo( props => {
172205
hasPanelModifiedIndicator={ props.hasPanelModifiedIndicator }
173206
/>
174207
</AdvancedControl>
208+
{ CimoDownloadNotice && <CimoDownloadNotice onDismiss={ () => setCimoDownloadNotice( null ) } /> }
209+
</>
175210
)
176211
} )
177212

src/init.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ public function register_block_editor_assets() {
349349
'version' => array_shift( $version_parts ),
350350
'wpVersion' => ! empty( $wp_version ) ? preg_replace( '/-.*/', '', $wp_version ) : $wp_version, // Ensure semver, strip out after dash
351351
'adminUrl' => admin_url(),
352+
'ajaxUrl' => admin_url('admin-ajax.php'),
352353

353354
// Fonts.
354355
'locale' => get_locale(),

0 commit comments

Comments
 (0)