Skip to content

Commit

Permalink
Add debouncer for clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Jan 16, 2025
1 parent f755f7a commit 9da297c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/ChatBlock/ChatMessageBubble.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
9 changes: 8 additions & 1 deletion src/ChatBlock/EmptyState.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Button } from 'semantic-ui-react';
import { debounce } from './utils';

function StarterMessage({ msg, onClick }) {
return (
Expand All @@ -15,6 +16,8 @@ function StarterMessage({ msg, onClick }) {
);
}

let click_signal = { current: null };

export default function EmptyState(props) {
const {
persona,
Expand All @@ -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,
)
}
/>
))}
Expand Down
10 changes: 10 additions & 0 deletions src/ChatBlock/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 9da297c

Please sign in to comment.