import { useEffect, useRef, useState } from "react"; import SlashCommandIcon from "./icons/SlashCommandIcon"; import { Tooltip } from "react-tooltip"; import ResetCommand from "./reset"; import EndAgentSession from "./endAgentSession"; import SlashPresets from "./SlashPresets"; import { useTranslation } from "react-i18next"; export default function SlashCommandsButton({ showing, setShowSlashCommand }) { const { t } = useTranslation(); return (
setShowSlashCommand(!showing)} className={`flex justify-center items-center cursor-pointer ${ showing ? "!opacity-100" : "" }`} >
); } export function SlashCommands({ showing, setShowing, sendCommand, promptRef }) { const cmdRef = useRef(null); useEffect(() => { function listenForOutsideClick() { if (!showing || !cmdRef.current) return false; document.addEventListener("click", closeIfOutside); } listenForOutsideClick(); }, [showing, cmdRef.current]); const closeIfOutside = ({ target }) => { if (target.id === "slash-cmd-btn") return; const isOutside = !cmdRef?.current?.contains(target); if (!isOutside) return; setShowing(false); }; return ( ); } export function useSlashCommands() { const [showSlashCommand, setShowSlashCommand] = useState(false); return { showSlashCommand, setShowSlashCommand }; }