fix: issues with chunk copy
This commit is contained in:
parent
8933131b4b
commit
340bef2175
1 changed files with 16 additions and 5 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ArrowLeft,
|
ArrowLeft,
|
||||||
|
Check,
|
||||||
Copy,
|
Copy,
|
||||||
File as FileIcon,
|
File as FileIcon,
|
||||||
Loader2,
|
Loader2,
|
||||||
|
|
@ -41,6 +42,9 @@ function ChunksPageContent() {
|
||||||
ChunkResult[]
|
ChunkResult[]
|
||||||
>([]);
|
>([]);
|
||||||
const [selectedChunks, setSelectedChunks] = useState<Set<number>>(new Set());
|
const [selectedChunks, setSelectedChunks] = useState<Set<number>>(new Set());
|
||||||
|
const [activeCopiedChunkIndex, setActiveCopiedChunkIndex] = useState<
|
||||||
|
number | null
|
||||||
|
>(null);
|
||||||
|
|
||||||
// Calculate average chunk length
|
// Calculate average chunk length
|
||||||
const averageChunkLength = useMemo(
|
const averageChunkLength = useMemo(
|
||||||
|
|
@ -70,8 +74,11 @@ function ChunksPageContent() {
|
||||||
}
|
}
|
||||||
}, [queryInputText, chunks]);
|
}, [queryInputText, chunks]);
|
||||||
|
|
||||||
const handleCopy = useCallback((text: string) => {
|
const handleCopy = useCallback((text: string, index: number) => {
|
||||||
navigator.clipboard.writeText(text);
|
// Trime whitespace and remove new lines/tabs for cleaner copy
|
||||||
|
navigator.clipboard.writeText(text.trim().replace(/[\n\r\t]/gm, ""));
|
||||||
|
setActiveCopiedChunkIndex(index);
|
||||||
|
setTimeout(() => setActiveCopiedChunkIndex(null), 30 * 1000); // 30 seconds
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const fileData = (data as File[]).find(
|
const fileData = (data as File[]).find(
|
||||||
|
|
@ -86,7 +93,7 @@ function ChunksPageContent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
setChunks(fileData?.chunks || []);
|
setChunks(fileData?.chunks || []);
|
||||||
}, [data, filename]);
|
}, [data, filename, setChunks, fileData]);
|
||||||
|
|
||||||
// Set selected state for all checkboxes when selectAll changes
|
// Set selected state for all checkboxes when selectAll changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -238,11 +245,15 @@ function ChunksPageContent() {
|
||||||
<div className="py-1">
|
<div className="py-1">
|
||||||
<Button
|
<Button
|
||||||
className="p-1"
|
className="p-1"
|
||||||
onClick={() => handleCopy(chunk.text)}
|
onClick={() => handleCopy(chunk.text, index)}
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="xs"
|
size="xs"
|
||||||
>
|
>
|
||||||
<Copy className="text-muted-foreground" />
|
{activeCopiedChunkIndex === index ? (
|
||||||
|
<Check className="text-muted-foreground" />
|
||||||
|
) : (
|
||||||
|
<Copy className="text-muted-foreground" />
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue