Skip to content

Commit 4bcae5c

Browse files
authored
fix: delete history (#659)
1 parent 76458db commit 4bcae5c

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/components/Common/HistoryList/HistoryListContent.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const HistoryListContent: FC<HistoryListContentProps> = ({
3333

3434
const [isOpen, setIsOpen] = useState(false);
3535
const [highlightId, setHighlightId] = useState<string>("");
36+
const [highlightItem, setHighlightItem] = useState<Chat>({} as Chat);
3637

3738
const sortedList = useMemo(() => {
3839
if (isNil(chats)) return {};
@@ -191,6 +192,15 @@ const HistoryListContent: FC<HistoryListContentProps> = ({
191192
};
192193
}, [highlightId, keyboardScroll, debouncedMouseScroll]);
193194

195+
const handleDelete = useCallback(() => {
196+
if (!highlightId) return;
197+
const currentIndex = flattenedChats.findIndex(
198+
(chat) => chat._id === highlightId
199+
);
200+
setHighlightItem(flattenedChats[currentIndex]);
201+
setIsOpen(true);
202+
}, [highlightId]);
203+
194204
if (chats.length === 0) {
195205
return (
196206
<div className="flex items-center justify-center flex-1 pt-8">
@@ -214,10 +224,8 @@ const HistoryListContent: FC<HistoryListContentProps> = ({
214224
onSelect={onSelect}
215225
onRename={onRename}
216226
onMouseEnter={() => setHighlightId(item._id)}
217-
onMouseLeave={() => setHighlightId("")}
218-
onBlur={() => setHighlightId("")}
219227
highlightId={highlightId}
220-
setIsOpen={setIsOpen}
228+
handleDelete={handleDelete}
221229
/>
222230
))}
223231
</ul>
@@ -227,7 +235,7 @@ const HistoryListContent: FC<HistoryListContentProps> = ({
227235

228236
<DeleteDialog
229237
isOpen={isOpen}
230-
active={active}
238+
active={active || highlightItem}
231239
setIsOpen={setIsOpen}
232240
handleRemove={handleRemove}
233241
/>

src/components/Common/HistoryList/HistoryListItem.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ interface HistoryListItemProps {
1414
onSelect: (chat: Chat) => void;
1515
onRename: (chatId: string, title: string) => void;
1616
onMouseEnter: () => void;
17-
onMouseLeave: () => void;
18-
onBlur: () => void;
19-
setIsOpen: (value: boolean) => void;
17+
handleDelete: () => void;
2018
highlightId: string;
2119
}
2220

@@ -26,16 +24,14 @@ const HistoryListItem: FC<HistoryListItemProps> = ({
2624
onSelect,
2725
onRename,
2826
onMouseEnter,
29-
onMouseLeave,
30-
onBlur,
3127
highlightId,
32-
setIsOpen,
28+
handleDelete,
3329
}) => {
3430
const { t } = useTranslation();
3531
const moreButtonRef = useRef<HTMLButtonElement>(null);
3632
const { _id, _source } = item;
3733
const title = _source?.title ?? _id;
38-
const isActive = item._id === active?._id || item._id === highlightId
34+
const isActive = item._id === active?._id || item._id === highlightId;
3935

4036
const [isEdit, setIsEdit] = useState(false);
4137

@@ -72,9 +68,7 @@ const HistoryListItem: FC<HistoryListItemProps> = ({
7268
icon: Trash2,
7369
shortcut: "D",
7470
iconColor: "#FF2018",
75-
onClick: () => {
76-
setIsOpen(true);
77-
},
71+
onClick: handleDelete,
7872
},
7973
];
8074

@@ -96,10 +90,7 @@ const HistoryListItem: FC<HistoryListItemProps> = ({
9690
onSelect(item);
9791
}}
9892
onMouseEnter={onMouseEnter}
99-
onMouseLeave={onMouseLeave}
100-
onBlur={onBlur}
10193
onContextMenu={onContextMenu}
102-
10394
>
10495
<div
10596
className={clsx("w-1 h-6 rounded-sm bg-[#0072FF]", {

0 commit comments

Comments
 (0)