mirror of
https://github.com/ItzCrazyKns/Perplexica.git
synced 2025-12-20 02:28:15 +00:00
feat(copy): fix type mismatch
This commit is contained in:
@@ -2,6 +2,7 @@ import { Check, ClipboardList } from 'lucide-react';
|
|||||||
import { Message } from '../ChatWindow';
|
import { Message } from '../ChatWindow';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Section } from '@/lib/hooks/useChat';
|
import { Section } from '@/lib/hooks/useChat';
|
||||||
|
import { SourceBlock } from '@/lib/types';
|
||||||
|
|
||||||
const Copy = ({
|
const Copy = ({
|
||||||
section,
|
section,
|
||||||
@@ -15,15 +16,24 @@ const Copy = ({
|
|||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
const sources = section.message.responseBlocks.filter(
|
||||||
|
(b) => b.type === 'source' && b.data.length > 0,
|
||||||
|
) as SourceBlock[];
|
||||||
|
|
||||||
const contentToCopy = `${initialMessage}${
|
const contentToCopy = `${initialMessage}${
|
||||||
section?.message.responseBlocks.filter((b) => b.type === 'source')
|
sources.length > 0 &&
|
||||||
?.length > 0 &&
|
`\n\nCitations:\n${sources
|
||||||
`\n\nCitations:\n${section.message.responseBlocks
|
.map((source) => source.data)
|
||||||
.filter((b) => b.type === 'source')
|
.flat()
|
||||||
?.map((source: any, i: any) => `[${i + 1}] ${source.metadata.url}`)
|
.map(
|
||||||
|
(s, i) =>
|
||||||
|
`[${i + 1}] ${s.metadata.url.startsWith('file_id://') ? s.metadata.fileName || 'Uploaded File' : s.metadata.url}`,
|
||||||
|
)
|
||||||
.join(`\n`)}`
|
.join(`\n`)}`
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
navigator.clipboard.writeText(contentToCopy);
|
navigator.clipboard.writeText(contentToCopy);
|
||||||
|
|
||||||
setCopied(true);
|
setCopied(true);
|
||||||
setTimeout(() => setCopied(false), 1000);
|
setTimeout(() => setCopied(false), 1000);
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user