Skip to content
Closed
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
161 changes: 84 additions & 77 deletions components/Common/Search/States/WithSearchBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import type { Results, Nullable } from '@orama/orama';
import classNames from 'classnames';
import { useState, useRef, useEffect } from 'react';
import type { FC } from 'react';
import FocusLock from 'react-focus-lock';
import { RemoveScroll } from 'react-remove-scroll';

import styles from '@/components/Common/Search/States/index.module.css';
import { WithAllResults } from '@/components/Common/Search/States/WithAllResults';
Expand Down Expand Up @@ -113,87 +115,92 @@ export const WithSearchBox: FC<SearchBoxProps> = ({ onClose }) => {
const selectedFacetName = Object.keys(facets)[selectedFacet];

return (
<div className={styles.searchBoxModalContainer}>
<div className={styles.searchBoxModalPanel} ref={searchBoxRef}>
<div className={styles.searchBoxInnerPanel}>
<div className={styles.searchBoxInputContainer}>
<button
onClick={onClose}
className={styles.searchBoxBackIconContainer}
>
<ChevronLeftIcon className={styles.searchBoxBackIcon} />
</button>

<MagnifyingGlassIcon
className={styles.searchBoxMagnifyingGlassIcon}
/>

<form onSubmit={onSubmit}>
<input
ref={searchInputRef}
type="search"
className={styles.searchBoxInput}
onChange={event => setSearchTerm(event.target.value)}
value={searchTerm}
/>
</form>
</div>

<div className={styles.fulltextSearchSections}>
{Object.keys(facets).map((facetName, idx) => (
<button
key={facetName}
className={classNames(styles.fulltextSearchSection, {
[styles.fulltextSearchSectionSelected]: selectedFacet === idx,
})}
onClick={() => changeFacet(idx)}
>
{facetName}
<span className={styles.fulltextSearchSectionCount}>
({facets[facetName].toLocaleString('en')})
</span>
</button>
))}
</div>

<div className={styles.fulltextResultsContainer}>
{searchError && <WithError />}

{!searchError && !searchTerm && <WithEmptyState />}

{!searchError && searchTerm && (
<>
{searchResults &&
searchResults.count > 0 &&
searchResults.hits.map(hit => (
<WithSearchResult
key={hit.id}
hit={hit}
searchTerm={searchTerm}
/>
))}

{searchResults && searchResults.count === 0 && (
<WithNoResults searchTerm={searchTerm} />
)}

{searchResults && searchResults.count > 8 && (
<WithAllResults
searchResults={searchResults}
searchTerm={searchTerm}
selectedFacetName={selectedFacetName}
onSeeAllClick={onClose}
<RemoveScroll>
<FocusLock>
<div className={styles.searchBoxModalContainer}>
<div className={styles.searchBoxModalPanel} ref={searchBoxRef}>
<div className={styles.searchBoxInnerPanel}>
<div className={styles.searchBoxInputContainer}>
<button
onClick={onClose}
className={styles.searchBoxBackIconContainer}
>
<ChevronLeftIcon className={styles.searchBoxBackIcon} />
</button>

<MagnifyingGlassIcon
className={styles.searchBoxMagnifyingGlassIcon}
/>

<form onSubmit={onSubmit}>
<input
ref={searchInputRef}
type="search"
className={styles.searchBoxInput}
onChange={event => setSearchTerm(event.target.value)}
value={searchTerm}
/>
</form>
</div>

<div className={styles.fulltextSearchSections}>
{Object.keys(facets).map((facetName, idx) => (
<button
key={facetName}
className={classNames(styles.fulltextSearchSection, {
[styles.fulltextSearchSectionSelected]:
selectedFacet === idx,
})}
onClick={() => changeFacet(idx)}
>
{facetName}
<span className={styles.fulltextSearchSectionCount}>
({facets[facetName].toLocaleString('en')})
</span>
</button>
))}
</div>

<div className={styles.fulltextResultsContainer}>
{searchError && <WithError />}

{!searchError && !searchTerm && <WithEmptyState />}

{!searchError && searchTerm && (
<>
{searchResults &&
searchResults.count > 0 &&
searchResults.hits.map(hit => (
<WithSearchResult
key={hit.id}
hit={hit}
searchTerm={searchTerm}
/>
))}

{searchResults && searchResults.count === 0 && (
<WithNoResults searchTerm={searchTerm} />
)}

{searchResults && searchResults.count > 8 && (
<WithAllResults
searchResults={searchResults}
searchTerm={searchTerm}
selectedFacetName={selectedFacetName}
onSeeAllClick={onClose}
/>
)}
</>
)}
</>
)}
</div>
</div>

<div className={styles.fulltextSearchFooter}>
<WithPoweredBy />
<div className={styles.fulltextSearchFooter}>
<WithPoweredBy />
</div>
</div>
</div>
</div>
</div>
</div>
</FocusLock>
</RemoveScroll>
);
};
139 changes: 128 additions & 11 deletions package-lock.json

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

Loading