-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathKapaPageLauncher.tsx
More file actions
88 lines (75 loc) · 1.89 KB
/
KapaPageLauncher.tsx
File metadata and controls
88 lines (75 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"use client";
import { Button, Stack, Text, Title } from "@mantine/core";
import { useEffect, useState } from "react";
declare global {
interface Window {
Kapa?: {
close?: () => void;
open?: (options?: {
mode?: "search" | "ai";
query?: string;
submit?: boolean;
}) => void;
render?: (options?: { onRender?: () => void }) => void;
unmount?: () => void;
};
}
}
export default function KapaPageLauncher() {
const [hasRendered, setHasRendered] = useState(false);
const openAssistant = () => {
if (!window.Kapa?.render) {
return;
}
window.Kapa.render({
onRender: () => {
setHasRendered(true);
window.Kapa?.open?.({ mode: "ai" });
},
});
};
useEffect(() => {
let cancelled = false;
const openWhenReady = () => {
if (cancelled) {
return;
}
if (!window.Kapa?.render) {
window.setTimeout(openWhenReady, 100);
return;
}
window.Kapa.render({
onRender: () => {
if (cancelled) {
return;
}
setHasRendered(true);
window.Kapa?.open?.({ mode: "ai" });
},
});
};
openWhenReady();
return () => {
cancelled = true;
window.Kapa?.close?.();
window.Kapa?.unmount?.();
};
}, []);
return (
<Stack gap="md" maw={640}>
<Title order={1}>Ask AI</Title>
<Text c="dimmed">
This branch gives Kapa a dedicated route, then opens the assistant in a
full-screen experience so the conversation gets most of the viewport.
</Text>
<Text c="dimmed">
{hasRendered
? "If you close the assistant, use the button below to open it again."
: "Loading the assistant..."}
</Text>
<Button w="fit-content" onClick={openAssistant}>
Open Ask AI
</Button>
</Stack>
);
}