Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
bruugey committed May 29, 2024
1 parent 3a3b11a commit 2f13c31
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/components/global/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import Link from 'next/link';
import { css } from '@emotion/css';
import Fuse, { IFuseOptions } from 'fuse.js';
import debounce from 'lodash/debounce';
// @ts-expect-error
import LockIcon from '@leafygreen-ui/icon/dist/Lock';
import { SearchInput, SearchResult } from '@leafygreen-ui/search-input';
import { spacing } from '@leafygreen-ui/tokens';
import { getSession, Session } from '@/auth';
import { components } from '@/utils/components';

const fuseOptions = {
Expand All @@ -18,6 +22,7 @@ const useFuseSearch = (data: any[], options: IFuseOptions<any>) => {
};

export function Search() {
const [session, setSession] = useState<Session | undefined>();
const [searchTerm, setSearchTerm] = useState('');
const [results, setResults] = useState(components);

Expand All @@ -43,14 +48,22 @@ export function Search() {
}
}, [searchTerm]);

useEffect(() => {
getSession().then(response => {
if (response !== null) {
setSession(response);
}
});
}, []);

return (
<SearchInput
aria-label="Search Components"
size="small"
value={searchTerm}
onChange={handleSearchChange}
className={css`
margin: 0 16px 24px 16px;
margin: ${spacing[400]}px ${spacing[600]}px;
`}
>
{results.map(item => (
Expand All @@ -66,10 +79,20 @@ export function Search() {
</div>
}
href={item.navPath ?? '/'}
// @ts-expect-error polymorphic error
// @ts-expect-error Polymorphic
as={Link}
>
{item.name}
<div
className={css`
display: flex;
align-items: center;
gap: ${spacing[200]}px;
`}
>
{item.name}
{item.isPrivate && !session?.user && <LockIcon size="small" />}
</div>
</SearchResult>
))}
</SearchInput>
Expand Down

0 comments on commit 2f13c31

Please sign in to comment.