Skip to content

Commit 2503fb4

Browse files
committed
Remove Kapa event listeners
1 parent 465529a commit 2503fb4

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

apps/webapp/app/hooks/useKapaWidget.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import { useShortcuts } from "../components/primitives/ShortcutsProvider";
33
import { useFeatures } from "~/hooks/useFeatures";
44
import { useCallback, useEffect, useState } from "react";
55

6+
declare global {
7+
interface Window {
8+
Kapa: (
9+
command: string,
10+
options?: () => void,
11+
remove?: string | { onRender?: () => void }
12+
) => void;
13+
}
14+
}
15+
616
export function useKapaWidget() {
717
const kapa = useKapaConfig();
818
const features = useFeatures();
@@ -20,17 +30,19 @@ export function useKapaWidget() {
2030
enableShortcuts();
2131
};
2232

33+
const handleModalOpen = () => {
34+
setIsKapaOpen(true);
35+
disableShortcuts();
36+
};
37+
2338
const kapaInterval = setInterval(() => {
2439
if (typeof window.Kapa === "function") {
2540
clearInterval(kapaInterval);
2641
window.Kapa("render");
2742
window.Kapa("onModalClose", handleModalClose);
2843

2944
// Register onModalOpen handler
30-
window.Kapa("onModalOpen", () => {
31-
setIsKapaOpen(true);
32-
disableShortcuts();
33-
});
45+
window.Kapa("onModalOpen", handleModalOpen);
3446
}
3547
}, 100);
3648

@@ -39,12 +51,13 @@ export function useKapaWidget() {
3951
clearInterval(kapaInterval);
4052
if (typeof window.Kapa === "function") {
4153
window.Kapa("unmount");
54+
55+
window.Kapa("onModalOpen", handleModalOpen, "remove");
56+
window.Kapa("onModalClose", handleModalClose, "remove");
4257
}
4358
};
4459
}, [features.isManagedCloud, kapa?.websiteId, disableShortcuts, enableShortcuts]);
4560

46-
//todo remove listeners
47-
4861
const openKapa = useCallback(() => {
4962
if (!features.isManagedCloud || !kapa?.websiteId) return;
5063

apps/webapp/app/root.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ import { useTypedMatchesData } from "./hooks/useTypedMatchData";
2525
import { getUser } from "./services/session.server";
2626
import { appEnvTitleTag } from "./utils";
2727

28-
declare global {
29-
interface Window {
30-
Kapa: (command: string, options?: (() => void) | { onRender?: () => void }) => void;
31-
}
32-
}
33-
3428
export const links: LinksFunction = () => {
3529
return [{ rel: "stylesheet", href: tailwindStylesheetUrl }];
3630
};

0 commit comments

Comments
 (0)