diff --git a/packages/frontend/src/components/projects/ProjectSearchBar/ProjectSearchBarDialog.tsx b/packages/frontend/src/components/projects/ProjectSearchBar/ProjectSearchBarDialog.tsx index 01f5b803..21f31901 100644 --- a/packages/frontend/src/components/projects/ProjectSearchBar/ProjectSearchBarDialog.tsx +++ b/packages/frontend/src/components/projects/ProjectSearchBar/ProjectSearchBarDialog.tsx @@ -8,18 +8,46 @@ import { Project } from 'gql-client'; import { useDebounce } from 'usehooks-ts'; import { ProjectSearchBarItem } from './ProjectSearchBarItem'; import { ProjectSearchBarEmpty } from './ProjectSearchBarEmpty'; +import { useNavigate } from 'react-router-dom'; +import { useCombobox } from 'downshift'; interface ProjectSearchBarDialogProps extends Dialog.DialogProps { onClose?: () => void; + onClickItem?: (data: Project) => void; } export const ProjectSearchBarDialog = ({ onClose, + onClickItem, ...props }: ProjectSearchBarDialogProps) => { const [items, setItems] = useState([]); - const [inputValue, setInputValue] = useState(''); + const [selectedItem, setSelectedItem] = useState(null); const client = useGQLClient(); + const navigate = useNavigate(); + + const { + getMenuProps, + getInputProps, + getItemProps, + inputValue, + setInputValue, + } = useCombobox({ + items, + itemToString(item) { + return item ? item.name : ''; + }, + selectedItem, + onSelectedItemChange: ({ selectedItem: newSelectedItem }) => { + if (newSelectedItem) { + setSelectedItem(newSelectedItem); + onClickItem?.(newSelectedItem); + navigate( + `/${newSelectedItem.organization.slug}/projects/${newSelectedItem.id}`, + ); + } + }, + }); const debouncedInputValue = useDebounce(inputValue, 500); @@ -42,7 +70,7 @@ export const ProjectSearchBarDialog = ({ setItems([]); onClose?.(); }; - console.log(items); + return ( @@ -50,28 +78,31 @@ export const ProjectSearchBarDialog = ({
} placeholder="Search" appearance="borderless" - value={inputValue} autoFocus - onChange={(e) => setInputValue(e.target.value)} />
{/* Content */} -
+
{items.length > 0 - ? items.map((item) => ( + ? items.map((item, index) => ( <>

Suggestions

- + )) : inputValue && } diff --git a/packages/frontend/src/pages/org-slug/layout.tsx b/packages/frontend/src/pages/org-slug/layout.tsx index 1ff1679f..36dade67 100644 --- a/packages/frontend/src/pages/org-slug/layout.tsx +++ b/packages/frontend/src/pages/org-slug/layout.tsx @@ -123,6 +123,7 @@ export const DashboardLayout = ({ setIsSearchOpen(false)} onClose={() => setIsSearchOpen(false)} />