Skip to content

Commit 6c27bf2

Browse files
committed
Lazyload SearchOrAskAiModal
1 parent dac1a5d commit 6c27bf2

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
.parcel-cache/
22
node_modules/
3-
_static/main.js
4-
_static/main.js.map
5-
_static/custom-elements.js
6-
_static/custom-elements.js.map
7-
_static/pages-nav.js
8-
_static/pages-nav.js.map
93
_static/styles.css
104
_static/styles.css.map
115
_static/*.woff2
6+
_static/*.js
7+
_static/*.js.map

src/Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi/SearchOrAskAiButton.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
/** @jsxImportSource @emotion/react */
12
import '../../eui-icons-cache'
2-
import { SearchOrAskAiModal } from './SearchOrAskAiModal'
33
import { useModalActions, useModalIsOpen } from './modal.store'
44
import { useSearchActions, useSearchTerm } from './search.store'
55
import {
@@ -10,10 +10,14 @@ import {
1010
EuiPanel,
1111
EuiTextTruncate,
1212
EuiText,
13+
EuiLoadingSpinner,
1314
} from '@elastic/eui'
1415
import { css } from '@emotion/react'
1516
import * as React from 'react'
16-
import { useEffect } from 'react'
17+
import { useEffect, Suspense, lazy } from 'react'
18+
19+
// Lazy load the modal component
20+
const SearchOrAskAiModal = lazy(() => import('./SearchOrAskAiModal').then(module => ({ default: module.SearchOrAskAiModal })))
1721

1822
export const SearchOrAskAiButton = () => {
1923
const searchTerm = useSearchTerm()
@@ -30,6 +34,13 @@ export const SearchOrAskAiButton = () => {
3034
max-width: 100%;
3135
`
3236

37+
const loadingCss = css`
38+
display: flex;
39+
justify-content: center;
40+
align-items: center;
41+
padding: 2rem;
42+
`
43+
3344
useEffect(() => {
3445
const handleKeydown = (event: KeyboardEvent) => {
3546
if (event.key === 'Escape') {
@@ -81,7 +92,13 @@ export const SearchOrAskAiButton = () => {
8192
<EuiOverlayMask>
8293
<EuiFocusTrap onClickOutside={closeModal}>
8394
<EuiPanel role="dialog" css={positionCss}>
84-
<SearchOrAskAiModal />
95+
<Suspense fallback={
96+
<div css={loadingCss}>
97+
<EuiLoadingSpinner size="xl" />
98+
</div>
99+
}>
100+
<SearchOrAskAiModal />
101+
</Suspense>
85102
</EuiPanel>
86103
</EuiFocusTrap>
87104
</EuiOverlayMask>

src/Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi/SearchOrAskAiModal.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ export const SearchOrAskAiModal = () => {
2020
const { setSearchTerm, submitAskAiTerm } = useSearchActions()
2121

2222
return (
23-
<EuiPanel
24-
css={css`
25-
max-height: 80vh;
26-
overflow: hidden;
27-
`}
28-
>
23+
<>
2924
<EuiFieldSearch
3025
fullWidth
3126
placeholder="Search the docs or ask Elastic Docs AI Assistant"
@@ -61,6 +56,6 @@ export const SearchOrAskAiModal = () => {
6156
This feature is in beta. Got feedback? We'd love to hear it!
6257
</EuiText>
6358
</div>
64-
</EuiPanel>
59+
</>
6560
)
6661
}

0 commit comments

Comments
 (0)