Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/www/src/components/docs/search.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
max-height: 440px;
}

.searchEmpty {
.searchEmpty,
.searchLoading {
display: flex;
align-items: center;
justify-content: center;
Expand Down
34 changes: 25 additions & 9 deletions apps/www/src/components/docs/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ import {
SpaceBetweenVerticallyIcon,
TextIcon
} from '@radix-ui/react-icons';
import { Command, Dialog, EmptyState, IconButton } from '@raystack/apsara';
import {
Command,
Dialog,
EmptyState,
IconButton,
Spinner
} from '@raystack/apsara';
import {
flattenTree,
type Item as PageItem,
Expand Down Expand Up @@ -106,6 +112,10 @@ export default function DocsSearch({ pageTree }: { pageTree: Root }) {

const trimmedQuery = search.trim();
const isSearching = trimmedQuery.length > 0;
// While fumadocs debounces + fetches, `query.data` is undefined. Without
// this flag the empty state would flash "No result found" for the duration
// of the request; instead we show a spinner until the fetch settles.
Comment thread
Shreyag02 marked this conversation as resolved.
Outdated
const isLoading = isSearching && query.isLoading;
const results =
isSearching && query.data && query.data !== 'empty' ? query.data : [];

Expand Down Expand Up @@ -228,14 +238,20 @@ export default function DocsSearch({ pageTree }: { pageTree: Root }) {
)}
</div>
<Command.Content className={styles.searchList}>
<Command.Empty className={styles.searchEmpty}>
<EmptyState
variant='empty1'
heading='No result found'
subHeading='The keyword you’re searching for isn’t in the document—try using a different term.'
icon={<ExclamationTriangleIcon />}
/>
</Command.Empty>
{isLoading ? (
<div className={styles.searchLoading}>
<Spinner size={5} aria-label='Searching docs' />
</div>
) : (
<Command.Empty className={styles.searchEmpty}>
<EmptyState
variant='empty1'
heading='No result found'
subHeading='The keyword you’re searching for isn’t in the document—try using a different term.'
icon={<ExclamationTriangleIcon />}
/>
</Command.Empty>
)}
Comment thread
Shreyag02 marked this conversation as resolved.
Outdated
{items.map((section, index) => (
<Fragment key={section.heading}>
<Command.Group>
Expand Down
Loading