Skip to content

Commit c98ecee

Browse files
committed
feat(spotlight-search): added spinner for loading state during loading state in spotlight search
1 parent e58e59e commit c98ecee

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

apps/www/src/components/docs/search.module.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
max-height: 440px;
2020
}
2121

22-
.searchEmpty {
22+
.searchEmpty,
23+
.searchLoading {
2324
display: flex;
2425
align-items: center;
2526
justify-content: center;

apps/www/src/components/docs/search.tsx

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ import {
1515
SpaceBetweenVerticallyIcon,
1616
TextIcon
1717
} from '@radix-ui/react-icons';
18-
import { Command, Dialog, EmptyState, IconButton } from '@raystack/apsara';
18+
import {
19+
Command,
20+
Dialog,
21+
EmptyState,
22+
IconButton,
23+
Spinner
24+
} from '@raystack/apsara';
1925
import {
2026
flattenTree,
2127
type Item as PageItem,
@@ -106,6 +112,10 @@ export default function DocsSearch({ pageTree }: { pageTree: Root }) {
106112

107113
const trimmedQuery = search.trim();
108114
const isSearching = trimmedQuery.length > 0;
115+
// While fumadocs debounces + fetches, `query.data` is undefined. Without
116+
// this flag the empty state would flash "No result found" for the duration
117+
// of the request; instead we show a spinner until the fetch settles.
118+
const isLoading = isSearching && query.isLoading;
109119
const results =
110120
isSearching && query.data && query.data !== 'empty' ? query.data : [];
111121

@@ -228,14 +238,20 @@ export default function DocsSearch({ pageTree }: { pageTree: Root }) {
228238
)}
229239
</div>
230240
<Command.Content className={styles.searchList}>
231-
<Command.Empty className={styles.searchEmpty}>
232-
<EmptyState
233-
variant='empty1'
234-
heading='No result found'
235-
subHeading='The keyword you’re searching for isn’t in the document—try using a different term.'
236-
icon={<ExclamationTriangleIcon />}
237-
/>
238-
</Command.Empty>
241+
{isLoading ? (
242+
<div className={styles.searchLoading}>
243+
<Spinner size={5} aria-label='Searching docs' />
244+
</div>
245+
) : (
246+
<Command.Empty className={styles.searchEmpty}>
247+
<EmptyState
248+
variant='empty1'
249+
heading='No result found'
250+
subHeading='The keyword you’re searching for isn’t in the document—try using a different term.'
251+
icon={<ExclamationTriangleIcon />}
252+
/>
253+
</Command.Empty>
254+
)}
239255
{items.map((section, index) => (
240256
<Fragment key={section.heading}>
241257
<Command.Group>

0 commit comments

Comments
 (0)