From 9da297cd66b1e22002bae8fc92879ea69624d6c2 Mon Sep 17 00:00:00 2001 From: Tiberiu Ichim Date: Thu, 16 Jan 2025 10:43:48 +0200 Subject: [PATCH] Add debouncer for clicks --- src/ChatBlock/ChatMessageBubble.jsx | 10 ++++++++-- src/ChatBlock/EmptyState.jsx | 9 ++++++++- src/ChatBlock/utils.js | 10 ++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/ChatBlock/ChatMessageBubble.jsx b/src/ChatBlock/ChatMessageBubble.jsx index ad2073e..31bf7f8 100644 --- a/src/ChatBlock/ChatMessageBubble.jsx +++ b/src/ChatBlock/ChatMessageBubble.jsx @@ -67,8 +67,14 @@ export function ToolCall({ tool_args, tool_name, tool_result }) { } export function ChatMessageBubble(props) { - const { message, isLoading, isMostRecent, libs, onChoice, showToolCalls } = - props; + const { + message, + isLoading, + isMostRecent, + libs, + onChoice, + showToolCalls, + } = props; const { remarkGfm } = libs; // , rehypePrism const { citations = {}, documents, type } = message; const isUser = type === 'user'; diff --git a/src/ChatBlock/EmptyState.jsx b/src/ChatBlock/EmptyState.jsx index 551ce50..b1ab173 100644 --- a/src/ChatBlock/EmptyState.jsx +++ b/src/ChatBlock/EmptyState.jsx @@ -1,4 +1,5 @@ import { Button } from 'semantic-ui-react'; +import { debounce } from './utils'; function StarterMessage({ msg, onClick }) { return ( @@ -15,6 +16,8 @@ function StarterMessage({ msg, onClick }) { ); } +let click_signal = { current: null }; + export default function EmptyState(props) { const { persona, @@ -36,7 +39,11 @@ export default function EmptyState(props) { key={msg.name} msg={msg} onClick={() => - onChoice(msg.message || `${msg.name}\n${msg.description}`) + debounce( + () => + onChoice(msg.message || `${msg.name}\n${msg.description}`), + click_signal, + ) } /> ))} diff --git a/src/ChatBlock/utils.js b/src/ChatBlock/utils.js index 2d1f73b..9f5826a 100644 --- a/src/ChatBlock/utils.js +++ b/src/ChatBlock/utils.js @@ -33,3 +33,13 @@ export const SVGIcon = ({ name, size, color, className, title }) => { /> ); }; + +export function debounce(callable, click_signal) { + if (!click_signal.current) { + click_signal.current = true; + setTimeout(() => { + click_signal.current = null; + }, 1000); + callable(); + } +}