mirror of https://github.com/msgbyte/tailchat
feat: 增加内置的文件发送功能
parent
a70c5e47a3
commit
469f34134c
@ -0,0 +1,17 @@
|
||||
import { Card } from '@capital/component';
|
||||
import React from 'react';
|
||||
import type { TagProps } from '../bbcode/type';
|
||||
|
||||
export const CardTag: React.FC<TagProps> = React.memo((props) => {
|
||||
const { node } = props;
|
||||
const label = node.content.join('');
|
||||
const attrs = node.attrs ?? {};
|
||||
|
||||
const payload: any = {
|
||||
label,
|
||||
...attrs,
|
||||
};
|
||||
|
||||
return <Card type={payload.type} payload={payload} />;
|
||||
});
|
||||
CardTag.displayName = 'CardTag';
|
@ -0,0 +1,45 @@
|
||||
import { downloadUrl } from '@/utils/file-helper';
|
||||
import React from 'react';
|
||||
import { Icon } from 'tailchat-design';
|
||||
import { useMemoizedFn, t } from 'tailchat-shared';
|
||||
import { IconBtn } from '../IconBtn';
|
||||
import { CardWrapper } from './Wrapper';
|
||||
|
||||
export interface FileCardPayload {
|
||||
label: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
export const FileCard: React.FC<{
|
||||
payload: FileCardPayload;
|
||||
}> = React.memo((props) => {
|
||||
const payload = props.payload ?? {};
|
||||
|
||||
const handleDownload = useMemoizedFn(() => {
|
||||
downloadUrl(payload.url, payload.label);
|
||||
});
|
||||
|
||||
return (
|
||||
<CardWrapper>
|
||||
<div className="flex items-center">
|
||||
<div className="mr-3 overflow-hidden">
|
||||
<div className="flex text-lg items-center">
|
||||
<Icon icon="mdi:paperclip" />
|
||||
<span className="ml-1">{t('文件')}</span>
|
||||
</div>
|
||||
|
||||
<div className="text-sm text-black text-opacity-60 dark:text-white dark:text-opacity-60">
|
||||
{payload.label}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<IconBtn
|
||||
title={t('下载')}
|
||||
icon="mdi:cloud-download-outline"
|
||||
onClick={handleDownload}
|
||||
/>
|
||||
</div>
|
||||
</CardWrapper>
|
||||
);
|
||||
});
|
||||
FileCard.displayName = 'FileCard';
|
@ -0,0 +1,14 @@
|
||||
import React from 'react';
|
||||
|
||||
export const CardWrapper: React.FC<React.PropsWithChildren> = React.memo(
|
||||
(props) => {
|
||||
return (
|
||||
<div className="w-3/4">
|
||||
<div className="border border-black border-opacity-20 rounded-md p-2 bg-black bg-opacity-5 dark:bg-black dark:bg-opacity-10 inline-flex overflow-hidden">
|
||||
{props.children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
);
|
||||
CardWrapper.displayName = 'CardWrapper';
|
@ -0,0 +1,17 @@
|
||||
import React from 'react';
|
||||
import { t } from 'tailchat-shared';
|
||||
import { FileCard, FileCardPayload } from './FileCard';
|
||||
import { CardWrapper } from './Wrapper';
|
||||
|
||||
interface Props {
|
||||
type: 'file';
|
||||
payload: FileCardPayload;
|
||||
}
|
||||
export const Card: React.FC<Props> = React.memo((props) => {
|
||||
if (props.type === 'file') {
|
||||
return <FileCard payload={props.payload} />;
|
||||
}
|
||||
|
||||
return <CardWrapper>{t('未知的卡片类型')}</CardWrapper>;
|
||||
});
|
||||
Card.displayName = 'Card';
|
Loading…
Reference in New Issue