2025-04-26 04:30:58 -04:00
|
|
|
import { useSetRecoilState, useResetRecoilState } from 'recoil';
|
2024-08-27 17:03:16 -04:00
|
|
|
import type { Artifact } from '~/common';
|
|
|
|
|
import FilePreview from '~/components/Chat/Input/Files/FilePreview';
|
|
|
|
|
import { useLocalize } from '~/hooks';
|
|
|
|
|
import { getFileType } from '~/utils';
|
|
|
|
|
import store from '~/store';
|
|
|
|
|
|
|
|
|
|
const ArtifactButton = ({ artifact }: { artifact: Artifact | null }) => {
|
|
|
|
|
const localize = useLocalize();
|
|
|
|
|
const setVisible = useSetRecoilState(store.artifactsVisible);
|
2025-04-26 04:30:58 -04:00
|
|
|
const setCurrentArtifactId = useSetRecoilState(store.currentArtifactId);
|
|
|
|
|
const resetCurrentArtifactId = useResetRecoilState(store.currentArtifactId);
|
2024-08-27 17:03:16 -04:00
|
|
|
if (artifact === null || artifact === undefined) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
const fileType = getFileType('artifact');
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="group relative my-4 rounded-xl text-sm text-text-primary">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => {
|
2025-04-26 04:30:58 -04:00
|
|
|
resetCurrentArtifactId();
|
2024-08-27 17:03:16 -04:00
|
|
|
setVisible(true);
|
2025-04-26 04:30:58 -04:00
|
|
|
setTimeout(() => {
|
|
|
|
|
setCurrentArtifactId(artifact.id);
|
|
|
|
|
}, 15);
|
2024-08-27 17:03:16 -04:00
|
|
|
}}
|
|
|
|
|
className="relative overflow-hidden rounded-xl border border-border-medium transition-all duration-300 hover:border-border-xheavy hover:shadow-lg"
|
|
|
|
|
>
|
2025-04-26 04:30:58 -04:00
|
|
|
<div className="w-fit bg-surface-tertiary p-2">
|
2024-08-27 17:03:16 -04:00
|
|
|
<div className="flex flex-row items-center gap-2">
|
|
|
|
|
<FilePreview fileType={fileType} className="relative" />
|
|
|
|
|
<div className="overflow-hidden text-left">
|
|
|
|
|
<div className="truncate font-medium">{artifact.title}</div>
|
|
|
|
|
<div className="truncate text-text-secondary">
|
|
|
|
|
{localize('com_ui_artifact_click')}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</button>
|
|
|
|
|
<br />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ArtifactButton;
|