-
-
Notifications
You must be signed in to change notification settings - Fork 548
feat/move-main-page-search-bar #4105
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,7 @@ import type { Organization } from 'types/organization' | |||||||||||||||||||
| import type { Project } from 'types/project' | ||||||||||||||||||||
| import type { MultiSearchBarProps, Suggestion } from 'types/search' | ||||||||||||||||||||
| import type { User } from 'types/user' | ||||||||||||||||||||
| import { cn } from 'utils/utility' | ||||||||||||||||||||
|
|
||||||||||||||||||||
| type SearchHit = Chapter | Event | Organization | Project | User | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -22,6 +23,9 @@ const MultiSearchBar: React.FC<MultiSearchBarProps> = ({ | |||||||||||||||||||
| indexes, | ||||||||||||||||||||
| initialValue = '', | ||||||||||||||||||||
| eventData, | ||||||||||||||||||||
| autoFocus = false, | ||||||||||||||||||||
| containerClassName, | ||||||||||||||||||||
| inputClassName, | ||||||||||||||||||||
| }) => { | ||||||||||||||||||||
| const [searchQuery, setSearchQuery] = useState(initialValue) | ||||||||||||||||||||
| const [suggestions, setSuggestions] = useState<Suggestion[]>([]) | ||||||||||||||||||||
|
|
@@ -115,6 +119,10 @@ const MultiSearchBar: React.FC<MultiSearchBarProps> = ({ | |||||||||||||||||||
|
|
||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||
| const handleKeyDown = (event: KeyboardEvent) => { | ||||||||||||||||||||
| const isInputFocused = document.activeElement === inputRef.current | ||||||||||||||||||||
| if (!isInputFocused && !showSuggestions) { | ||||||||||||||||||||
| return | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if (event.key === 'Escape') { | ||||||||||||||||||||
| setShowSuggestions(false) | ||||||||||||||||||||
| inputRef.current?.blur() | ||||||||||||||||||||
|
|
@@ -158,8 +166,6 @@ const MultiSearchBar: React.FC<MultiSearchBarProps> = ({ | |||||||||||||||||||
| }, [searchQuery, suggestions, highlightedIndex, handleSuggestionClick]) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||
| inputRef.current?.focus() | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const handleClickOutside = (event: MouseEvent) => { | ||||||||||||||||||||
| if (searchBarRef.current && !searchBarRef.current.contains(event.target as Node)) { | ||||||||||||||||||||
| setShowSuggestions(false) | ||||||||||||||||||||
|
|
@@ -173,6 +179,12 @@ const MultiSearchBar: React.FC<MultiSearchBarProps> = ({ | |||||||||||||||||||
| } | ||||||||||||||||||||
| }, []) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||
| if (autoFocus) { | ||||||||||||||||||||
| inputRef.current?.focus() | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+182
to
+185
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: The autoFocus feature fails when the component mounts with Prompt for AI agents
Suggested change
|
||||||||||||||||||||
| }, [autoFocus]) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const handleSearchChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||||||||||||||||||||
| const newQuery = e.target.value | ||||||||||||||||||||
| setSearchQuery(newQuery) | ||||||||||||||||||||
|
|
@@ -221,7 +233,7 @@ const MultiSearchBar: React.FC<MultiSearchBarProps> = ({ | |||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return ( | ||||||||||||||||||||
| <div className="w-full max-w-md p-4" ref={searchBarRef}> | ||||||||||||||||||||
| <div className={cn('w-full max-w-md p-4', containerClassName)} ref={searchBarRef}> | ||||||||||||||||||||
| <div className="relative"> | ||||||||||||||||||||
| {isLoaded ? ( | ||||||||||||||||||||
| <> | ||||||||||||||||||||
|
|
@@ -236,7 +248,10 @@ const MultiSearchBar: React.FC<MultiSearchBarProps> = ({ | |||||||||||||||||||
| onChange={handleSearchChange} | ||||||||||||||||||||
| onFocus={handleFocusSearch} | ||||||||||||||||||||
| placeholder={placeholder} | ||||||||||||||||||||
| className="h-12 w-full rounded-lg border-1 border-gray-300 bg-white pr-10 pl-10 text-lg text-black focus:ring-1 focus:ring-blue-500 focus:outline-hidden dark:border-gray-600 dark:bg-gray-800 dark:text-white dark:focus:ring-blue-300" | ||||||||||||||||||||
| className={cn( | ||||||||||||||||||||
| 'h-12 w-full rounded-lg border-1 border-gray-300 bg-white pr-10 pl-10 text-lg text-black focus:ring-1 focus:ring-blue-500 focus:outline-hidden dark:border-gray-600 dark:bg-gray-800 dark:text-white dark:focus:ring-blue-300', | ||||||||||||||||||||
| inputClassName | ||||||||||||||||||||
| )} | ||||||||||||||||||||
| /> | ||||||||||||||||||||
| {searchQuery && ( | ||||||||||||||||||||
| <button | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Event search functionality will be lost when MultiSearchBar is moved to global Header. The component relies on
eventData={data?.upcomingEvents ?? []}from page-specific GraphQL query, but the relocated component in Header.tsx does not receive this prop. Since events are not in the Algoliaindexesarray, search will silently return no event results.Prompt for AI agents