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

implement real time suggestion #292

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions frontend/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ beforeEach(() => {
})
})
jest.mock('@algolia/autocomplete-theme-classic', () => ({}))
import React from 'react'
Rajgupta36 marked this conversation as resolved.
Show resolved Hide resolved

global.React = React
global.TextEncoder = TextEncoder
16 changes: 3 additions & 13 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"watch": "jest --watch"
},
"dependencies": {
"@algolia/autocomplete-js": "^1.17.8",
"@algolia/autocomplete-plugin-query-suggestions": "^1.17.8",
"@algolia/autocomplete-theme-classic": "^1.17.8",
"@fortawesome/fontawesome-svg-core": "^6.7.0",
"@fortawesome/free-brands-svg-icons": "^6.7.0",
"@fortawesome/free-regular-svg-icons": "^6.7.0",
Expand Down Expand Up @@ -45,9 +48,6 @@
"tailwind-merge": "^2.5.4"
},
"devDependencies": {
"@algolia/autocomplete-js": "^1.17.8",
"@algolia/autocomplete-plugin-query-suggestions": "^1.17.8",
"@algolia/autocomplete-theme-classic": "^1.17.8",
"@eslint/js": "^9.15.0",
"@swc/core": "^1.10.4",
"@swc/jest": "^0.2.37",
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/components/AutoSuggestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { debounce } from 'lodash'
import React from 'react'
import { useEffect, useRef } from 'react'
import { NEST_ENV } from 'utils/credentials'
import { client } from '../lib/algoliaClient'
import './Autosuggestion.css'
import { client } from 'lib/algoliaClient'
import 'components/Autosuggestion.css'

interface SearchProps {
onChange: (query: string) => void
Expand Down Expand Up @@ -45,7 +45,6 @@ const Autocomplete = React.memo(
container: containerRef.current,
placeholder,
autoFocus: true,
openOnFocus: true,
insights: true,
plugins: [querySuggestionsPlugin],
initialState: { query: initialValue },
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback } from 'react'
import Autocomplete from './AutoSuggestion'
import Autocomplete from 'components/AutoSuggestion'

interface SearchProps {
onSearch: (query: string) => void
Expand Down
33 changes: 15 additions & 18 deletions frontend/src/components/SearchPageLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ const SearchPageLayout = ({

return (
<div className="mt-16 flex min-h-screen w-full flex-col items-center justify-normal p-5 text-text">
{!isLoaded && !isSearchBarReady && (
<div className="bg-background/50 fixed inset-0 flex items-center justify-center">
<LoadingSpinner imageUrl={loadingImageUrl} />
</div>
)}
<div className="w-full max-w-lg">
<SearchBar
indexName={indexName}
Expand All @@ -54,23 +49,25 @@ const SearchPageLayout = ({
onReady={handleSearchBarReady}
/>
</div>
{!isLoaded ? (
{!isSearchBarReady || !isLoaded ? (
<div className="mt-20 flex h-64 w-full items-center justify-center">
<LoadingSpinner imageUrl={loadingImageUrl} />
</div>
) : (
<div>
{totalPages === 0 && <div className="text bg:text-white m-4 text-xl">{empty}</div>}
{children}
</div>
)}
{totalPages > 1 && (
<Pagination
currentPage={currentPage}
totalPages={totalPages}
onPageChange={onPageChange}
isLoaded={isLoaded}
/>
<>
<div>
{totalPages === 0 && <div className="text bg:text-white m-4 text-xl">{empty}</div>}
{children}
</div>
{totalPages > 1 && (
<Pagination
currentPage={currentPage}
totalPages={totalPages}
onPageChange={onPageChange}
isLoaded={isLoaded}
/>
)}
</>
)}
</div>
)
Expand Down
Loading