Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add new orama search widget #264

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion app/components/ClientOnlySearchButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { Suspense } from 'react'
import { ImSpinner2 } from 'react-icons/im'

const LazySearchButton = React.lazy(() =>
import('@orama/searchbox').then((mod) => ({ default: mod.SearchButton }))
import('@orama/react-components').then((mod) => ({
default: mod.OramaSearchButton,
}))
)

let defaultMounted = false
Expand Down
36 changes: 23 additions & 13 deletions app/components/DocsLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
useNavigate,
useParams,
} from '@tanstack/react-router'
import type { AnyOrama, SearchParamsFullText, AnyDocument } from '@orama/orama'
import { SearchBox } from '@orama/searchbox'
import { OramaSearchBox } from '@orama/react-components'
import { Carbon } from '~/components/Carbon'
import { Select } from '~/components/Select'
import { useLocalStorage } from '~/utils/useLocalStorage'
Expand Down Expand Up @@ -336,6 +335,8 @@
[menuConfig]
)

const [isSearchboxOpen, setIsSearchboxOpen] = React.useState(false)

const docsMatch = matches.find((d) => d.pathname.includes('/docs'))

const relativePathname = lastMatch.pathname.replace(
Expand Down Expand Up @@ -444,15 +445,6 @@
)
})

const oramaSearchParams: SearchParamsFullText<AnyOrama, AnyDocument> = {
threshold: 0,
where: {
category: {
eq: capitalize(libraryId),
},
},
}

const logo = (
<DocsLogo
name={name}
Expand Down Expand Up @@ -499,7 +491,12 @@
onSelect={versionConfig.onSelect}
/>
</div>
<ClientOnlySearchButton {...searchButtonParams} />
<ClientOnlySearchButton
{...searchButtonParams}
onClick={() => setIsSearchboxOpen(true)}
>
Search
</ClientOnlySearchButton>
{menuItems}
</div>
</details>
Expand Down Expand Up @@ -546,7 +543,20 @@
className={`min-h-screen flex flex-col lg:flex-row w-full transition-all duration-300`}
>
<div className="fixed z-50">
<SearchBox {...searchBoxParams} searchParams={oramaSearchParams} />
<OramaSearchBox
{...searchBoxParams}
searchParams={{
threshold: 0,
where: {
category: {
eq: capitalize(libraryId!) as string,
},
} as any,
}}
facetProperty={undefined}
open={isSearchboxOpen}
onSearchboxClosed={() => setIsSearchboxOpen(false)}
/>
</div>
{smallMenu}
{largeMenu}
Expand Down Expand Up @@ -625,7 +635,7 @@
key={partner.name}
className="overflow-hidden hover:bg-gray-500/10 dark:hover:bg-gray-500/10 transition-colors"
>
<a

Check warning on line 638 in app/components/DocsLayout.tsx

View workflow job for this annotation

GitHub Actions / PR

Using target="_blank" without rel="noreferrer" (which implies rel="noopener") is a security risk in older browsers: see https://mathiasbynens.github.io/rel-noopener/#recommendations
href={partner.href}
target="_blank"
className="px-4 flex items-center justify-center cursor-pointer"
Expand Down
40 changes: 15 additions & 25 deletions app/components/Orama.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
import type {
RegisterSearchButtonProps,
RegisterSearchBoxProps,
} from '@orama/searchbox'
import { OramaClient } from '@oramacloud/client'
import '@orama/searchbox/dist/index.css'

const oramaInstance = new OramaClient({
// The search endpoint for the Orama index
endpoint: 'https://cloud.orama.run/v1/indexes/tanstack-dev-ur0ppd',
// The public API key for performing search. This is commit-safe.
api_key: 'xqfn8QcuImADRGPIlhWTo9cT5UNiqPDj',
})

export const searchBoxParams: RegisterSearchBoxProps = {
oramaInstance,
colorScheme: 'system',
backdrop: true,
export const searchBoxParams = {
index: {
api_key: 'xqfn8QcuImADRGPIlhWTo9cT5UNiqPDj',
endpoint: 'https://cloud.orama.run/v1/indexes/tanstack-dev-ur0ppd',
},
colorScheme: 'system' as 'light' | 'dark' | 'system',
facetProperty: 'category',
resultsMap: {
resultMap: {
description: 'content',
section: 'category',
},

themeConfig: {
light: {},
dark: {
'--backdrop-bg-color': '#0d103591',
colors: {
light: {},
dark: {
'--backdrop-background-color-primary': 'rgba(0, 0, 0, 0.7)',
},
},
},
searchMode: 'hybrid',
searchParams: {
threshold: 0,
},
}

export const searchButtonParams: RegisterSearchButtonProps = {
export const searchButtonParams = {
colorScheme: 'system',
fullWidth: true,
}
17 changes: 14 additions & 3 deletions app/routes/_libraries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { CgClose, CgMenuLeft, CgMusicSpeaker } from 'react-icons/cg'
import { MdLibraryBooks, MdSupport } from 'react-icons/md'
import { twMerge } from 'tailwind-merge'
import { SearchBox } from '@orama/searchbox'
import { OramaSearchBox } from '@orama/react-components'
import { sortBy } from '~/utils/utils'
import logoColor100w from '~/images/logo-color-100w.png'
import {
Expand Down Expand Up @@ -46,6 +46,8 @@ function LibrariesLayout() {

const [mounted, setMounted] = React.useState(false)

const [onSearchboxOpen, setOnSearchboxOpen] = React.useState(false)

React.useEffect(() => {
setMounted(true)
}, [])
Expand Down Expand Up @@ -255,7 +257,12 @@ function LibrariesLayout() {
{logo}
</div>
<div className="p-2">
<ClientOnlySearchButton {...searchButtonParams} />
<ClientOnlySearchButton
{...searchButtonParams}
onClick={() => setOnSearchboxOpen(true)}
>
Search
</ClientOnlySearchButton>
</div>
<div className="flex-1 flex flex-col gap-4 whitespace-nowrap overflow-y-auto text-base pb-[300px]">
<div className="space-y-1 text-sm p-2 border-b border-gray-500/10 dark:border-gray-500/20">
Expand All @@ -278,7 +285,11 @@ function LibrariesLayout() {
</div>
{mounted ? (
<div className="fixed z-50">
<SearchBox {...searchBoxParams} />
<OramaSearchBox
{...searchBoxParams}
open={onSearchboxOpen}
onSearchboxClosed={() => setOnSearchboxOpen(false)}
/>
</div>
) : null}
</div>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@octokit/graphql": "^7.0.2",
"@octokit/rest": "^20.0.2",
"@orama/searchbox": "1.0.0-rc42",
"@orama/react-components": "^0.0.22",
"@oramacloud/client": "^1.2.2",
"@remix-run/node": "^2.8.1",
"@sentry/react": "^8.2.1",
Expand Down
Loading
Loading