-
Notifications
You must be signed in to change notification settings - Fork 141
fix: support cmd+k to open the search modal
#1755
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
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 |
|---|---|---|
|
|
@@ -4,8 +4,8 @@ import RouterLink from '@docusaurus/Link'; | |
| // import { useHistory, useLocation } from '@docusaurus/router'; | ||
| import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; | ||
| import clsx from 'clsx'; | ||
| // import React, { useCallback } from 'react'; | ||
| import React, { useEffect, useState } from 'react'; | ||
| import { useHotkeys } from 'react-hotkeys-hook'; | ||
|
|
||
| // import { ApifySearch } from '@apify/docs-search-modal'; | ||
| import { ControlKeyIcon, SearchIcon } from '@apify/docs-search-modal/dist/utils/icons'; | ||
|
|
@@ -82,6 +82,7 @@ export function Link(props) { | |
|
|
||
| export default function SearchBar({ onClick }) { | ||
| const [variant, setVariant] = useState(null); | ||
| const [opened, setOpened] = useState(false); | ||
| const { siteConfig } = useDocusaurusContext(); | ||
| const { inkeepApiKey } = siteConfig.customFields; | ||
|
|
||
|
|
@@ -98,9 +99,18 @@ export default function SearchBar({ onClick }) { | |
| }, []); | ||
|
|
||
| onClick = () => { | ||
| if (opened) { | ||
| return; | ||
| } | ||
|
|
||
| setOpened(true); | ||
|
|
||
| if (variant === 'kapa') { | ||
| if (window.Kapa && typeof window.Kapa.open === 'function') { | ||
| window.Kapa.open(); | ||
| window.Kapa('onModalClose', () => { | ||
| setOpened(false); | ||
| }); | ||
| } else { | ||
| console.error('Kapa.ai widget is not available.'); | ||
| } | ||
|
|
@@ -178,11 +188,13 @@ export default function SearchBar({ onClick }) { | |
| }, | ||
| ], | ||
| }, | ||
| defaultView: 'chat', | ||
| }; | ||
| const modal = window.Inkeep.ModalSearchAndChat(config); | ||
|
|
||
| function handleOpenChange(newOpen) { | ||
| modal.update({ modalSettings: { isOpen: newOpen } }); | ||
| setOpened(newOpen); | ||
|
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. Bug: SearchBar Prop Ignored, State Not ResetThe |
||
| } | ||
|
|
||
| modal.update({ modalSettings: { isOpen: true } }); | ||
|
|
@@ -200,6 +212,10 @@ export default function SearchBar({ onClick }) { | |
| } | ||
| }, []); | ||
|
|
||
| useHotkeys('mod+k, /', () => { | ||
| onClick(); | ||
| }, { preventDefault: true }); | ||
|
|
||
| return ( | ||
| <BrowserOnly> | ||
| {() => ( | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Bug: Kapa.ai Integration Causes Search Bar Issues
The search bar component exhibits two issues related to the Kapa.ai integration:
onModalCloseevent listeners, leading to multiplesetOpened(false)calls and potential memory leaks when the modal closes.openedstate is set totruebut never reset tofalse, permanently preventing any subsequent attempts to open the search modal.