mirror of
https://github.com/block/goose.git
synced 2026-07-17 12:56:20 +02:00
cleanup memory in chat (#4073)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import remarkGfm from 'remark-gfm';
|
||||
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
||||
@@ -17,16 +17,31 @@ interface MarkdownContentProps {
|
||||
|
||||
const CodeBlock = ({ language, children }: { language: string; children: string }) => {
|
||||
const [copied, setCopied] = useState(false);
|
||||
const timeoutRef = useRef<number | null>(null);
|
||||
|
||||
const handleCopy = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(children);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 2000); // Reset after 2 seconds
|
||||
|
||||
if (timeoutRef.current) {
|
||||
window.clearTimeout(timeoutRef.current);
|
||||
}
|
||||
|
||||
timeoutRef.current = window.setTimeout(() => setCopied(false), 2000);
|
||||
} catch (err) {
|
||||
console.error('Failed to copy text: ', err);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (timeoutRef.current) {
|
||||
window.clearTimeout(timeoutRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="relative group w-full">
|
||||
<button
|
||||
|
||||
@@ -141,11 +141,16 @@ export default function ProgressiveMessageList({
|
||||
|
||||
// Force complete rendering when search is active
|
||||
useEffect(() => {
|
||||
// Only add listener if we're actually loading
|
||||
if (!isLoading) {
|
||||
return;
|
||||
}
|
||||
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
const isMac = window.electron.platform === 'darwin';
|
||||
const isSearchShortcut = (isMac ? e.metaKey : e.ctrlKey) && e.key === 'f';
|
||||
|
||||
if (isSearchShortcut && isLoading) {
|
||||
if (isSearchShortcut) {
|
||||
// Immediately render all messages when search is triggered
|
||||
setRenderedCount(messages.length);
|
||||
setIsLoading(false);
|
||||
@@ -248,14 +253,14 @@ export default function ProgressiveMessageList({
|
||||
renderedCount,
|
||||
renderMessage,
|
||||
isUserMessage,
|
||||
hasContextHandlerContent,
|
||||
getContextHandlerType,
|
||||
chat,
|
||||
append,
|
||||
appendMessage,
|
||||
toolCallNotifications,
|
||||
onScrollToBottom,
|
||||
isStreamingMessage,
|
||||
hasContextHandlerContent,
|
||||
getContextHandlerType,
|
||||
onScrollToBottom,
|
||||
]);
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user