Fix: Accidentally deleted the previously selected chat. (#17710)

This commit is contained in:
balibabu
2026-08-03 13:45:35 +08:00
committed by GitHub
parent a1a79ab98c
commit 62457075d4
4 changed files with 41 additions and 11 deletions

View File

@@ -10,5 +10,5 @@ export const useHandleSearchStrChange = () => {
[],
);
return { handleInputChange, searchString };
return { handleInputChange, searchString, setSearchString };
};

View File

@@ -273,7 +273,8 @@ export const useFetchChat = () => {
export const useFetchSessionList = () => {
const { id } = useParams();
const { searchString, handleInputChange } = useHandleSearchStrChange();
const { searchString, handleInputChange, setSearchString } =
useHandleSearchStrChange();
const {
data,
@@ -299,7 +300,14 @@ export const useFetchSessionList = () => {
},
});
return { data, loading, refetch, searchString, handleInputChange };
return {
data,
loading,
refetch,
searchString,
handleInputChange,
setSearchString,
};
};
export function useFetchSessionManually() {

View File

@@ -83,10 +83,22 @@ export function Sessions({ handleConversationCardClick }: SessionProps) {
});
}, []);
// Selected items that are still visible under the current search filter.
// Batch deletion and the selected count must act on this set — selectedIds
// alone would include items filtered out of view by the search.
const visibleSelectedIds = useMemo(
() =>
conversationList.filter((x) => selectedIds.has(x.id)).map((x) => x.id),
[conversationList, selectedIds],
);
// Toggle select all
const toggleSelectAll = useCallback(() => {
setSelectedIds((prev) => {
if (prev.size === conversationList.length) {
const allVisibleSelected =
conversationList.length > 0 &&
conversationList.every((x) => prev.has(x.id));
if (allVisibleSelected) {
return new Set();
}
return new Set(conversationList.map((x) => x.id));
@@ -95,20 +107,19 @@ export function Sessions({ handleConversationCardClick }: SessionProps) {
// Batch delete
const handleBatchDelete = useCallback(async () => {
if (selectedIds.size === 0) {
if (visibleSelectedIds.length === 0) {
return;
}
const selectedIdList = Array.from(selectedIds);
const currentConversationDeleted = conversationId
? selectedIdList.includes(conversationId)
? visibleSelectedIds.includes(conversationId)
: false;
const temporaryIdSet = new Set(
conversationList.filter((item) => item.is_new).map((item) => item.id),
);
const persistedIds: string[] = [];
selectedIdList.forEach((id) => {
visibleSelectedIds.forEach((id) => {
if (temporaryIdSet.has(id)) {
removeTemporaryConversation(id);
} else {
@@ -131,7 +142,7 @@ export function Sessions({ handleConversationCardClick }: SessionProps) {
}
exitSelectionMode();
}, [
selectedIds,
visibleSelectedIds,
conversationId,
conversationList,
setConversationBoth,
@@ -140,7 +151,7 @@ export function Sessions({ handleConversationCardClick }: SessionProps) {
exitSelectionMode,
]);
const selectedCount = useMemo(() => selectedIds.size, [selectedIds]);
const selectedCount = visibleSelectedIds.length;
const { id } = useParams();
const { showEmbedModal, hideEmbedModal, embedVisible, beta } =

View File

@@ -30,6 +30,7 @@ export const useSelectDerivedConversationList = () => {
loading,
handleInputChange,
searchString,
setSearchString,
} = useFetchSessionList();
const { id: dialogId } = useParams();
@@ -38,6 +39,9 @@ export const useSelectDerivedConversationList = () => {
const addTemporaryConversation = useCallback(() => {
const conversationId = generateConversationId();
// Clear the search keyword, otherwise the newly created session will be
// filtered out by the search after it is persisted and refetched.
setSearchString('');
setList((pre) => {
if (dialogId) {
setConversationBoth(conversationId, 'true');
@@ -61,7 +65,14 @@ export const useSelectDerivedConversationList = () => {
return pre;
});
}, [dialogId, setConversationBoth, t, prologue, conversationList]);
}, [
dialogId,
setConversationBoth,
t,
prologue,
conversationList,
setSearchString,
]);
const removeTemporaryConversation = useCallback((conversationId: string) => {
setList((prevList) => {