7
7
*/
8
8
import Icon from 'components/Icon/Icon.react' ;
9
9
import { Link } from 'react-router-dom' ;
10
- import React , { useEffect , useRef , useState } from 'react' ;
10
+ import React , { lazy , Suspense , useState , useRef , useEffect } from 'react' ;
11
11
import Popover from 'components/Popover/Popover.react' ;
12
12
import Position from 'lib/Position' ;
13
13
import styles from 'components/Sidebar/B4aSidebar.scss' ;
14
14
import { amplitudeLogEvent } from 'lib/amplitudeEvents' ;
15
- import B4aApiIcon from 'components/Sidebar/icons/B4aApiIcon.react' ;
16
- import B4aDatabaseIcon from 'components/Sidebar/icons/B4aDatabaseIcon.react' ;
17
- import B4aCloudCodeIcon from 'components/Sidebar/icons/B4aCloudCodeIcon.react' ;
18
- import B4aWebDeploymentIcon from 'components/Sidebar/icons/B4aWebDeploymentIcon.react' ;
19
- import B4aMoreIcon from 'components/Sidebar/icons/B4aMoreIcon.react' ;
20
- import B4aOverviewIcon from 'components/Sidebar/icons/B4aOverviewIcon.react' ;
21
- import B4aAppSettingsIcon from 'components/Sidebar/icons/B4aAppSettingsIcon.react' ;
15
+
16
+ const LazyB4aApiIcon = lazy ( ( ) => import ( 'components/Sidebar/icons/B4aApiIcon.react' ) ) ;
17
+ const LazyB4aDatabaseIcon = lazy ( ( ) => import ( 'components/Sidebar/icons/B4aDatabaseIcon.react' ) ) ;
18
+ const LazyB4aCloudCodeIcon = lazy ( ( ) => import ( 'components/Sidebar/icons/B4aCloudCodeIcon.react' ) ) ;
19
+ const LazyB4aWebDeploymentIcon = lazy ( ( ) => import ( 'components/Sidebar/icons/B4aWebDeploymentIcon.react' ) ) ;
20
+ const LazyB4aMoreIcon = lazy ( ( ) => import ( 'components/Sidebar/icons/B4aMoreIcon.react' ) ) ;
21
+ const LazyB4aOverviewIcon = lazy ( ( ) => import ( 'components/Sidebar/icons/B4aOverviewIcon.react' ) ) ;
22
+ const LazyB4aAppSettingsIcon = lazy ( ( ) => import ( 'components/Sidebar/icons/B4aAppSettingsIcon.react' ) ) ;
23
+
24
+ // Preload functions for each lazy icon
25
+ LazyB4aApiIcon . preload = ( ) => import ( 'components/Sidebar/icons/B4aApiIcon.react' ) ;
26
+ LazyB4aDatabaseIcon . preload = ( ) => import ( 'components/Sidebar/icons/B4aDatabaseIcon.react' ) ;
27
+ LazyB4aCloudCodeIcon . preload = ( ) => import ( 'components/Sidebar/icons/B4aCloudCodeIcon.react' ) ;
28
+ LazyB4aWebDeploymentIcon . preload = ( ) => import ( 'components/Sidebar/icons/B4aWebDeploymentIcon.react' ) ;
29
+ LazyB4aMoreIcon . preload = ( ) => import ( 'components/Sidebar/icons/B4aMoreIcon.react' ) ;
30
+ LazyB4aOverviewIcon . preload = ( ) => import ( 'components/Sidebar/icons/B4aOverviewIcon.react' ) ;
31
+ LazyB4aAppSettingsIcon . preload = ( ) => import ( 'components/Sidebar/icons/B4aAppSettingsIcon.react' ) ;
22
32
23
33
const sendEvent = ( ) => {
24
34
// eslint-disable-next-line no-undef
@@ -29,19 +39,47 @@ const sendEvent = () => {
29
39
const getIconContent = ( icon ) => {
30
40
switch ( icon ) {
31
41
case 'b4a-api-icon' :
32
- return < B4aApiIcon /> ;
42
+ return (
43
+ < Suspense fallback = { null } >
44
+ < LazyB4aApiIcon />
45
+ </ Suspense >
46
+ ) ;
33
47
case 'b4a-database-icon' :
34
- return < B4aDatabaseIcon /> ;
48
+ return (
49
+ < Suspense fallback = { null } >
50
+ < LazyB4aDatabaseIcon />
51
+ </ Suspense >
52
+ ) ;
35
53
case 'b4a-cloud-code-icon' :
36
- return < B4aCloudCodeIcon /> ;
54
+ return (
55
+ < Suspense fallback = { null } >
56
+ < LazyB4aCloudCodeIcon />
57
+ </ Suspense >
58
+ ) ;
37
59
case 'b4a-web-deployment-icon' :
38
- return < B4aWebDeploymentIcon /> ;
60
+ return (
61
+ < Suspense fallback = { null } >
62
+ < LazyB4aWebDeploymentIcon />
63
+ </ Suspense >
64
+ ) ;
39
65
case 'b4a-more-icon' :
40
- return < B4aMoreIcon /> ;
66
+ return (
67
+ < Suspense fallback = { null } >
68
+ < LazyB4aMoreIcon />
69
+ </ Suspense >
70
+ ) ;
41
71
case 'b4a-app-overview-icon' :
42
- return < B4aOverviewIcon /> ;
72
+ return (
73
+ < Suspense fallback = { null } >
74
+ < LazyB4aOverviewIcon />
75
+ </ Suspense >
76
+ ) ;
43
77
case 'b4a-app-settings-icon' :
44
- return < B4aAppSettingsIcon /> ;
78
+ return (
79
+ < Suspense fallback = { null } >
80
+ < LazyB4aAppSettingsIcon />
81
+ </ Suspense >
82
+ ) ;
45
83
default :
46
84
return null ;
47
85
}
@@ -53,6 +91,17 @@ const B4aSidebarSection = ({ active, children, name, link, icon, style, primaryB
53
91
const [ position , setPosition ] = useState ( null ) ;
54
92
const subSectionRef = useRef ( ) ;
55
93
94
+ // Preload all icons on mount
95
+ useEffect ( ( ) => {
96
+ LazyB4aApiIcon . preload ( ) ;
97
+ LazyB4aDatabaseIcon . preload ( ) ;
98
+ LazyB4aCloudCodeIcon . preload ( ) ;
99
+ LazyB4aWebDeploymentIcon . preload ( ) ;
100
+ LazyB4aMoreIcon . preload ( ) ;
101
+ LazyB4aOverviewIcon . preload ( ) ;
102
+ LazyB4aAppSettingsIcon . preload ( ) ;
103
+ } , [ ] ) ;
104
+
56
105
useEffect ( ( ) => {
57
106
if ( showPopoverSection ) {
58
107
const node = subSectionRef . current ;
0 commit comments