Files
ragflow/web/src/pages/next-chats/chat/use-add-box.ts
balibabu ea38e12d42 Feat: Users can chat directly without first creating a conversation. #11768 (#11769)
### What problem does this PR solve?

Feat: Users can chat directly without first creating a conversation.
#11768
### Type of change


- [x] New Feature (non-breaking change which adds functionality)
2025-12-05 17:34:41 +08:00

33 lines
733 B
TypeScript

import { useCallback, useEffect, useState } from 'react';
import { v4 as uuid } from 'uuid';
export function useAddChatBox(isDebugMode: boolean) {
const [ids, setIds] = useState<string[]>([uuid()]);
const hasSingleChatBox = ids.length === 1;
const hasThreeChatBox = ids.length === 3;
const addChatBox = useCallback(() => {
setIds((prev) => [...prev, uuid()]);
}, []);
const removeChatBox = useCallback((id: string) => {
setIds((prev) => prev.filter((x) => x !== id));
}, []);
useEffect(() => {
if (!isDebugMode) {
setIds((pre) => pre.slice(0, 1));
}
}, [isDebugMode]);
return {
chatBoxIds: ids,
hasSingleChatBox,
hasThreeChatBox,
addChatBox,
removeChatBox,
};
}