refactor: improve history item hover states and interactions
Browse files
app/components/sidebar/HistoryItem.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import * as Dialog from '@radix-ui/react-dialog';
|
| 2 |
-
import { useEffect, useRef, useState } from 'react';
|
| 3 |
import { type ChatHistoryItem } from '~/lib/persistence';
|
| 4 |
import WithTooltip from '~/components/ui/Tooltip';
|
| 5 |
|
|
@@ -11,78 +10,46 @@ interface HistoryItemProps {
|
|
| 11 |
}
|
| 12 |
|
| 13 |
export function HistoryItem({ item, onDelete, onDuplicate, exportChat }: HistoryItemProps) {
|
| 14 |
-
const [hovering, setHovering] = useState(false);
|
| 15 |
-
const hoverRef = useRef<HTMLDivElement>(null);
|
| 16 |
-
|
| 17 |
-
useEffect(() => {
|
| 18 |
-
let timeout: NodeJS.Timeout | undefined;
|
| 19 |
-
|
| 20 |
-
function mouseEnter() {
|
| 21 |
-
setHovering(true);
|
| 22 |
-
|
| 23 |
-
if (timeout) {
|
| 24 |
-
clearTimeout(timeout);
|
| 25 |
-
}
|
| 26 |
-
}
|
| 27 |
-
|
| 28 |
-
function mouseLeave() {
|
| 29 |
-
setHovering(false);
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
hoverRef.current?.addEventListener('mouseenter', mouseEnter);
|
| 33 |
-
hoverRef.current?.addEventListener('mouseleave', mouseLeave);
|
| 34 |
-
|
| 35 |
-
return () => {
|
| 36 |
-
hoverRef.current?.removeEventListener('mouseenter', mouseEnter);
|
| 37 |
-
hoverRef.current?.removeEventListener('mouseleave', mouseLeave);
|
| 38 |
-
};
|
| 39 |
-
}, []);
|
| 40 |
-
|
| 41 |
return (
|
| 42 |
-
<div
|
| 43 |
-
ref={hoverRef}
|
| 44 |
-
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"
|
| 45 |
-
>
|
| 46 |
<a href={`/chat/${item.urlId}`} className="flex w-full relative truncate block">
|
| 47 |
{item.description}
|
| 48 |
<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%">
|
| 49 |
-
|
| 50 |
-
<
|
| 51 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
<button
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
onClick={(event) => {
|
| 55 |
event.preventDefault();
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
//exportChat(item.messages, item.description);
|
| 59 |
}}
|
| 60 |
-
title="Export chat"
|
| 61 |
/>
|
| 62 |
</WithTooltip>
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
<button
|
| 66 |
-
className="i-ph:copy scale-110 mr-2"
|
| 67 |
-
onClick={() => onDuplicate?.(item.id)}
|
| 68 |
-
title="Duplicate chat"
|
| 69 |
-
/>
|
| 70 |
-
</WithTooltip>
|
| 71 |
-
)}
|
| 72 |
-
<Dialog.Trigger asChild>
|
| 73 |
-
<WithTooltip tooltip="Delete chat">
|
| 74 |
-
<button
|
| 75 |
-
className="i-ph:trash scale-110"
|
| 76 |
-
onClick={(event) => {
|
| 77 |
-
// we prevent the default so we don't trigger the anchor above
|
| 78 |
-
event.preventDefault();
|
| 79 |
-
onDelete?.(event);
|
| 80 |
-
}}
|
| 81 |
-
/>
|
| 82 |
-
</WithTooltip>
|
| 83 |
-
</Dialog.Trigger>
|
| 84 |
-
</div>
|
| 85 |
-
)}
|
| 86 |
</div>
|
| 87 |
</a>
|
| 88 |
</div>
|
|
|
|
| 1 |
import * as Dialog from '@radix-ui/react-dialog';
|
|
|
|
| 2 |
import { type ChatHistoryItem } from '~/lib/persistence';
|
| 3 |
import WithTooltip from '~/components/ui/Tooltip';
|
| 4 |
|
|
|
|
| 10 |
}
|
| 11 |
|
| 12 |
export function HistoryItem({ item, onDelete, onDuplicate, exportChat }: HistoryItemProps) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
return (
|
| 14 |
+
<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">
|
|
|
|
|
|
|
|
|
|
| 15 |
<a href={`/chat/${item.urlId}`} className="flex w-full relative truncate block">
|
| 16 |
{item.description}
|
| 17 |
<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%">
|
| 18 |
+
<div className="flex items-center p-1 text-bolt-elements-textSecondary opacity-0 group-hover:opacity-100 transition-opacity">
|
| 19 |
+
<WithTooltip tooltip="Export chat">
|
| 20 |
+
<button
|
| 21 |
+
type="button"
|
| 22 |
+
className="i-ph:download-simple scale-110 mr-2 hover:text-bolt-elements-item-contentAccent"
|
| 23 |
+
onClick={(event) => {
|
| 24 |
+
event.preventDefault();
|
| 25 |
+
exportChat(item.id);
|
| 26 |
+
}}
|
| 27 |
+
title="Export chat"
|
| 28 |
+
/>
|
| 29 |
+
</WithTooltip>
|
| 30 |
+
{onDuplicate && (
|
| 31 |
+
<WithTooltip tooltip="Duplicate chat">
|
| 32 |
<button
|
| 33 |
+
type="button"
|
| 34 |
+
className="i-ph:copy scale-110 mr-2 hover:text-bolt-elements-item-contentAccent"
|
| 35 |
+
onClick={() => onDuplicate?.(item.id)}
|
| 36 |
+
title="Duplicate chat"
|
| 37 |
+
/>
|
| 38 |
+
</WithTooltip>
|
| 39 |
+
)}
|
| 40 |
+
<Dialog.Trigger asChild>
|
| 41 |
+
<WithTooltip tooltip="Delete chat">
|
| 42 |
+
<button
|
| 43 |
+
type="button"
|
| 44 |
+
className="i-ph:trash scale-110 hover:text-bolt-elements-button-danger-text"
|
| 45 |
onClick={(event) => {
|
| 46 |
event.preventDefault();
|
| 47 |
+
onDelete?.(event);
|
|
|
|
|
|
|
| 48 |
}}
|
|
|
|
| 49 |
/>
|
| 50 |
</WithTooltip>
|
| 51 |
+
</Dialog.Trigger>
|
| 52 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
</div>
|
| 54 |
</a>
|
| 55 |
</div>
|