2024-08-21 05:58:43 +00:00
|
|
|
import * as Dialog from '@radix-ui/react-dialog';
|
|
|
|
import { type ChatHistoryItem } from '~/lib/persistence';
|
2024-11-22 09:05:18 +00:00
|
|
|
import WithTooltip from '~/components/ui/Tooltip';
|
2024-08-01 14:54:59 +00:00
|
|
|
|
2024-08-21 05:58:43 +00:00
|
|
|
interface HistoryItemProps {
|
|
|
|
item: ChatHistoryItem;
|
|
|
|
onDelete?: (event: React.UIEvent) => void;
|
2024-11-17 19:03:40 +00:00
|
|
|
onDuplicate?: (id: string) => void;
|
2024-11-22 22:23:45 +00:00
|
|
|
exportChat: (id?: string) => void;
|
2024-08-21 05:58:43 +00:00
|
|
|
}
|
|
|
|
|
2024-11-22 22:23:45 +00:00
|
|
|
export function HistoryItem({ item, onDelete, onDuplicate, exportChat }: HistoryItemProps) {
|
2024-08-01 14:54:59 +00:00
|
|
|
return (
|
2024-11-25 15:16:17 +00:00
|
|
|
<div className="group rounded-md text-bolt-elements-textSecondary hover:text-bolt-elements-textPrimary hover:bg-bolt-elements-background-depth-3 overflow-hidden flex justify-between items-center px-2 py-1">
|
2024-08-01 14:54:59 +00:00
|
|
|
<a href={`/chat/${item.urlId}`} className="flex w-full relative truncate block">
|
|
|
|
{item.description}
|
2024-11-22 08:17:28 +00:00
|
|
|
<div className="absolute right-0 z-1 top-0 bottom-0 bg-gradient-to-l from-bolt-elements-background-depth-2 group-hover:from-bolt-elements-background-depth-3 box-content pl-3 to-transparent w-10 flex justify-end group-hover:w-15 group-hover:from-99%">
|
2024-11-25 15:16:17 +00:00
|
|
|
<div className="flex items-center p-1 text-bolt-elements-textSecondary opacity-0 group-hover:opacity-100 transition-opacity">
|
|
|
|
<WithTooltip tooltip="Export chat">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="i-ph:download-simple scale-110 mr-2 hover:text-bolt-elements-item-contentAccent"
|
|
|
|
onClick={(event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
exportChat(item.id);
|
|
|
|
}}
|
|
|
|
title="Export chat"
|
|
|
|
/>
|
|
|
|
</WithTooltip>
|
|
|
|
{onDuplicate && (
|
|
|
|
<WithTooltip tooltip="Duplicate chat">
|
2024-11-17 19:03:40 +00:00
|
|
|
<button
|
2024-11-25 15:16:17 +00:00
|
|
|
type="button"
|
|
|
|
className="i-ph:copy scale-110 mr-2 hover:text-bolt-elements-item-contentAccent"
|
|
|
|
onClick={() => onDuplicate?.(item.id)}
|
|
|
|
title="Duplicate chat"
|
|
|
|
/>
|
|
|
|
</WithTooltip>
|
|
|
|
)}
|
|
|
|
<Dialog.Trigger asChild>
|
|
|
|
<WithTooltip tooltip="Delete chat">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="i-ph:trash scale-110 hover:text-bolt-elements-button-danger-text"
|
2024-11-22 09:05:18 +00:00
|
|
|
onClick={(event) => {
|
|
|
|
event.preventDefault();
|
2024-11-25 15:16:17 +00:00
|
|
|
onDelete?.(event);
|
2024-11-22 09:05:18 +00:00
|
|
|
}}
|
2024-11-17 19:03:40 +00:00
|
|
|
/>
|
2024-11-22 09:05:18 +00:00
|
|
|
</WithTooltip>
|
2024-11-25 15:16:17 +00:00
|
|
|
</Dialog.Trigger>
|
|
|
|
</div>
|
2024-08-01 14:54:59 +00:00
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|