Skip to content

Commit 5d7f3c8

Browse files
committed
Allow passing in a query
1 parent 2503fb4 commit 5d7f3c8

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

apps/webapp/app/hooks/useKapaWidget.tsx

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import { useCallback, useEffect, useState } from "react";
55

66
declare global {
77
interface Window {
8-
Kapa: (
8+
Kapa: ((
99
command: string,
1010
options?: () => void,
1111
remove?: string | { onRender?: () => void }
12-
) => void;
12+
) => void) & {
13+
open: (options?: { mode: string; query: string; submit: boolean }) => void;
14+
};
1315
}
1416
}
1517

@@ -58,15 +60,26 @@ export function useKapaWidget() {
5860
};
5961
}, [features.isManagedCloud, kapa?.websiteId, disableShortcuts, enableShortcuts]);
6062

61-
const openKapa = useCallback(() => {
62-
if (!features.isManagedCloud || !kapa?.websiteId) return;
63+
const openKapa = useCallback(
64+
(query?: string) => {
65+
if (!features.isManagedCloud || !kapa?.websiteId) return;
6366

64-
if (typeof window.Kapa === "function") {
65-
window.Kapa("open");
66-
setIsKapaOpen(true);
67-
disableShortcuts();
68-
}
69-
}, [disableShortcuts, features.isManagedCloud, kapa?.websiteId]);
67+
if (typeof window.Kapa === "function") {
68+
window.Kapa.open(
69+
query
70+
? {
71+
mode: "ai",
72+
query,
73+
submit: true,
74+
}
75+
: undefined
76+
);
77+
setIsKapaOpen(true);
78+
disableShortcuts();
79+
}
80+
},
81+
[disableShortcuts, features.isManagedCloud, kapa?.websiteId]
82+
);
7083

7184
return {
7285
isKapaEnabled: features.isManagedCloud && kapa?.websiteId,

0 commit comments

Comments
 (0)