Skip to content

Commit

Permalink
fix: load kapa only once (#2009)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr authored Jan 17, 2025
1 parent b0ca0cf commit 548a519
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/theme/KapaWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ import "./KapaWidget.css"

export default function KapaWidget() {
const [isScriptLoaded, setIsScriptLoaded] = useState(false)
const [child, setChild] = useState<HTMLScriptElement | undefined>()

const loadKapaWidget = () => {
console.log("Kapai", window.Kapa)

if (isScriptLoaded) {
document.body.removeChild(child)
return
}

const script = document.createElement("script")
Expand All @@ -30,15 +27,15 @@ export default function KapaWidget() {
script.setAttribute("data-project-logo", "/docs/img/kapa-logo.png")
script.setAttribute("data-consent-required", "true")
script.setAttribute("data-button-hide", "true")
script.setAttribute("data-modal-override-open-id", "custom-button-id")
script.setAttribute("data-modal-override-open-id", "kapa-ai-button")
script.setAttribute("data-modal-open-by-default", "true")
script.onload = () => setIsScriptLoaded(true)
setChild(document.body.appendChild(script))
document.body.appendChild(script)
}

return (
<button
id="custom-button-id"
id="kapa-ai-button"
className="mantine-UnstyledButton-root mantine-Button-root mantine-124rx6h"
type="button"
data-button="true"
Expand Down

0 comments on commit 548a519

Please sign in to comment.