Skip to content

Commit 3e4fa6e

Browse files
committed
feat: update search box
1 parent cabd9df commit 3e4fa6e

File tree

3 files changed

+41
-25
lines changed

3 files changed

+41
-25
lines changed

apps/docs/src/app/search-index/[page]/route.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { getOramaDocuments } from '@/lib/orama/orama-document';
22
import { docs } from '@/lib/source';
33

44
import { getLocale } from 'next-intl/server';
5-
import { notFound } from 'next/navigation';
65

76
import { NextResponse } from 'next/server';
87

apps/docs/src/components/search-dialog.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export default function CustomSearchDialog(props: SharedProps) {
2424
[config],
2525
);
2626
const docId = getDocId(locale, pathname);
27-
const { isPages, appTag, pagesTag, whereTag } = parseDocId(docId);
27+
const { isPages, version, isVLatest, appTag, pagesTag, whereTag } =
28+
parseDocId(docId);
2829

2930
return (
3031
<SearchOrama
@@ -33,8 +34,8 @@ export default function CustomSearchDialog(props: SharedProps) {
3334
whereTag={whereTag}
3435
allowClear
3536
tags={[
36-
{ name: 'App', value: appTag },
37-
{ name: 'Pages', value: pagesTag },
37+
{ name: isVLatest ? 'App' : `App(v${version})`, value: appTag },
38+
{ name: isVLatest ? 'Pages' : `Pages(v${version})`, value: pagesTag },
3839
]}
3940
client={client}
4041
showOrama

apps/docs/src/components/search-orama.tsx

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ import {
77
import { useOnChange } from 'fumadocs-core/utils/use-on-change';
88
import {
99
SearchDialog,
10+
SearchDialogClose,
11+
SearchDialogContent,
12+
SearchDialogFooter,
13+
SearchDialogHeader,
14+
SearchDialogIcon,
15+
SearchDialogInput,
16+
SearchDialogList,
17+
SearchDialogOverlay,
1018
type SharedProps,
11-
type TagItem,
1219
TagsList,
20+
TagsListItem,
1321
} from 'fumadocs-ui/components/dialog/search';
1422
import { type ReactNode, useState } from 'react';
1523

@@ -20,7 +28,7 @@ export interface OramaSearchDialogProps extends SharedProps {
2028
footer?: ReactNode;
2129
defaultTag?: string;
2230
whereTag?: string;
23-
tags?: TagItem[];
31+
tags?: { name: string; value: string }[];
2432

2533
/**
2634
* Add the "Powered by Orama" label
@@ -49,13 +57,14 @@ export default function OramaSearchDialog({
4957
showOrama = false,
5058
allowClear = false,
5159
index,
60+
footer,
5261
...props
5362
}: OramaSearchDialogProps): ReactNode {
5463
const [tag, setTag] = useState(defaultTag);
5564
let where = {};
5665
if (whereTag) {
5766
where = {
58-
tag: { in: [...new Set([tag, whereTag])] },
67+
tag: [...new Set([tag, whereTag])],
5968
};
6069
}
6170
const { search, setSearch, query } = useDocsSearch(
@@ -80,27 +89,34 @@ export default function OramaSearchDialog({
8089
<SearchDialog
8190
search={search}
8291
onSearchChange={setSearch}
83-
results={query.data ?? []}
8492
isLoading={query.isLoading}
8593
{...props}
86-
footer={
87-
tags ? (
88-
<>
89-
<TagsList
90-
tag={tag}
91-
onTagChange={setTag}
92-
items={tags}
93-
allowClear={allowClear}
94-
>
95-
{showOrama ? <Label /> : null}
94+
>
95+
<SearchDialogOverlay />
96+
<SearchDialogContent>
97+
<SearchDialogHeader>
98+
<SearchDialogIcon />
99+
<SearchDialogInput />
100+
<SearchDialogClose />
101+
</SearchDialogHeader>
102+
{query.data !== 'empty' && query.data && (
103+
<SearchDialogList items={query.data} />
104+
)}
105+
<SearchDialogFooter className="flex flex-row">
106+
{tags ? (
107+
<TagsList tag={tag} onTagChange={setTag} allowClear={allowClear}>
108+
{tags.map(({ name, value }) => (
109+
<TagsListItem key={name} value={value}>
110+
{name}
111+
</TagsListItem>
112+
))}
96113
</TagsList>
97-
{props.footer}
98-
</>
99-
) : (
100-
props.footer
101-
)
102-
}
103-
/>
114+
) : null}
115+
{showOrama ? <Label /> : null}
116+
{footer}
117+
</SearchDialogFooter>
118+
</SearchDialogContent>
119+
</SearchDialog>
104120
);
105121
}
106122

0 commit comments

Comments
 (0)