mirror of https://github.com/buster-so/buster.git
remove old file card components
This commit is contained in:
parent
caf51eae15
commit
fc795f9a3b
|
@ -1,16 +1,14 @@
|
|||
'use client';
|
||||
|
||||
import { BusterChatMessageReasoning_file } from '@/api/asset_interfaces';
|
||||
import {
|
||||
AppCodeBlockWrapper,
|
||||
SyntaxHighlighterLightTheme
|
||||
} from '@/components/ui/typography/AppCodeBlock';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { SyntaxHighlighterLightTheme } from '@/components/ui/typography/AppCodeBlock';
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import { AnimatePresence, motion } from 'framer-motion';
|
||||
import { Text } from '@/components/ui/typography';
|
||||
import pluralize from 'pluralize';
|
||||
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
||||
import { TextAndVersionPill } from '../../typography/TextAndVersionPill';
|
||||
import { FileCard } from '../../card/FileCard';
|
||||
|
||||
const style = SyntaxHighlighterLightTheme;
|
||||
|
||||
|
@ -118,11 +116,14 @@ export const StreamingMessageCode: React.FC<
|
|||
}, [text, modified]);
|
||||
|
||||
return (
|
||||
<AppCodeBlockWrapper
|
||||
title={<TextAndVersionPill fileName={file_name} versionNumber={version_number} />}
|
||||
language={'yaml'}
|
||||
showCopyButton={false}
|
||||
buttons={buttons}>
|
||||
<FileCard
|
||||
fileName={useMemo(
|
||||
() => (
|
||||
<TextAndVersionPill fileName={file_name} versionNumber={version_number} />
|
||||
),
|
||||
[file_name, version_number]
|
||||
)}
|
||||
headerButtons={buttons}>
|
||||
<AnimatePresence initial={!isCompletedStream}>
|
||||
<motion.div
|
||||
className="w-full overflow-x-auto p-3"
|
||||
|
@ -143,7 +144,7 @@ export const StreamingMessageCode: React.FC<
|
|||
))}
|
||||
</motion.div>
|
||||
</AnimatePresence>
|
||||
</AppCodeBlockWrapper>
|
||||
</FileCard>
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
'use client';
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import React from 'react';
|
||||
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
||||
import lightTheme from './light';
|
||||
import { AppCodeBlockWrapper } from './AppCodeBlockWrapper';
|
||||
import { cn } from '@/lib/classMerge';
|
||||
import { useMemoizedFn } from '@/hooks';
|
||||
import { useBusterNotifications } from '@/context/BusterNotifications';
|
||||
import { FileCard } from '../../card/FileCard';
|
||||
import { Button } from '../../buttons';
|
||||
import { Copy } from '../../icons';
|
||||
|
||||
export const AppCodeBlock: React.FC<{
|
||||
language?: string;
|
||||
|
@ -27,6 +31,13 @@ export const AppCodeBlock: React.FC<{
|
|||
} = props;
|
||||
const style = lightTheme;
|
||||
const code = String(children).replace(/\n$/, '');
|
||||
const { openSuccessMessage } = useBusterNotifications();
|
||||
|
||||
const copyCode = useMemoizedFn(() => {
|
||||
if (!code) return;
|
||||
navigator.clipboard.writeText(code);
|
||||
openSuccessMessage('Copied to clipboard');
|
||||
});
|
||||
|
||||
//this is a huge assumption, but if there is no language, it is probably an inline code block
|
||||
if (!language) {
|
||||
|
@ -34,11 +45,16 @@ export const AppCodeBlock: React.FC<{
|
|||
}
|
||||
|
||||
return (
|
||||
<AppCodeBlockWrapper
|
||||
<FileCard
|
||||
fileName={title || language}
|
||||
className={wrapperClassName}
|
||||
code={code}
|
||||
language={title || language}
|
||||
showCopyButton={showCopyButton}>
|
||||
headerButtons={
|
||||
showCopyButton && (
|
||||
<Button variant="ghost" onClick={copyCode} prefix={<Copy />}>
|
||||
Copy
|
||||
</Button>
|
||||
)
|
||||
}>
|
||||
<div className="w-full overflow-x-auto">
|
||||
<div className="code-wrapper">
|
||||
{language ? (
|
||||
|
@ -56,7 +72,7 @@ export const AppCodeBlock: React.FC<{
|
|||
)}
|
||||
</div>
|
||||
</div>
|
||||
</AppCodeBlockWrapper>
|
||||
</FileCard>
|
||||
);
|
||||
});
|
||||
AppCodeBlock.displayName = 'AppCodeBlock';
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
import { useBusterNotifications } from '@/context/BusterNotifications';
|
||||
import React from 'react';
|
||||
import { Text } from '@/components/ui/typography';
|
||||
import { useMemoizedFn } from '@/hooks';
|
||||
import { Button } from '@/components/ui/buttons';
|
||||
import { Copy } from '@/components/ui/icons';
|
||||
import { cn } from '@/lib/classMerge';
|
||||
|
||||
export const AppCodeBlockWrapper: React.FC<{
|
||||
children: React.ReactNode;
|
||||
code?: string;
|
||||
language?: string;
|
||||
showCopyButton?: boolean;
|
||||
buttons?: React.ReactNode;
|
||||
title?: string | React.ReactNode;
|
||||
className?: string;
|
||||
}> = React.memo(
|
||||
({ children, code, showCopyButton = true, language, buttons, title, className }) => {
|
||||
const { openSuccessMessage } = useBusterNotifications();
|
||||
|
||||
const copyCode = useMemoizedFn(() => {
|
||||
if (!code) return;
|
||||
navigator.clipboard.writeText(code);
|
||||
openSuccessMessage('Copied to clipboard');
|
||||
});
|
||||
|
||||
return (
|
||||
<div className={cn('overflow-hidden rounded border', 'max-h-fit', className)}>
|
||||
<div
|
||||
className={cn(
|
||||
'bg-item-active border-border max-h-[32px] min-h-[32px] border-b px-2.5',
|
||||
'flex items-center justify-between'
|
||||
)}>
|
||||
<Text className="pl-2">{title || language}</Text>
|
||||
<div className="flex items-center space-x-1">
|
||||
{showCopyButton && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
copyCode();
|
||||
}}
|
||||
prefix={<Copy />}>
|
||||
Copy
|
||||
</Button>
|
||||
)}
|
||||
{buttons}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
AppCodeBlockWrapper.displayName = 'CodeBlockWrapper';
|
|
@ -1,5 +1,5 @@
|
|||
export * from './AppCodeBlock';
|
||||
export * from './AppCodeBlockWrapper';
|
||||
|
||||
import SyntaxHighlighterLightTheme from './light';
|
||||
import SyntaxHighlighterDarkTheme from './dark';
|
||||
|
||||
|
|
Loading…
Reference in New Issue