fix: fix new chat title subscription
This commit is contained in:
parent
cf41cb1874
commit
e361ec0cee
|
@ -82,20 +82,25 @@ export function Avatar(props: { role: Message["role"] }) {
|
|||
export function ChatItem(props: {
|
||||
onClick?: () => void;
|
||||
onDelete?: () => void;
|
||||
onEdit?: (title: string) => void;
|
||||
title: string;
|
||||
count: number;
|
||||
time: string;
|
||||
selected: boolean;
|
||||
}) {
|
||||
const updateTitle = useChatStore((state) => state.updateTitle);
|
||||
|
||||
const [isEditingTitle, setIsEditingTitle] = useState(false);
|
||||
const [title, setTitle] = useState(props.title);
|
||||
|
||||
useEffect(() => {
|
||||
setTitle(props.title);
|
||||
}, [props.title]);
|
||||
|
||||
function editCompleted() {
|
||||
setIsEditingTitle(false);
|
||||
// Blank will be restored to its original state
|
||||
if (!title) setTitle(props.title);
|
||||
props.onEdit && props.onEdit(title);
|
||||
updateTitle(title);
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -146,19 +151,14 @@ export function ChatItem(props: {
|
|||
}
|
||||
|
||||
export function ChatList() {
|
||||
const [
|
||||
sessions,
|
||||
selectedIndex,
|
||||
selectSession,
|
||||
removeSession,
|
||||
editDialogTitle,
|
||||
] = useChatStore((state) => [
|
||||
state.sessions,
|
||||
state.currentSessionIndex,
|
||||
state.selectSession,
|
||||
state.removeSession,
|
||||
state.updateSessionTitle,
|
||||
]);
|
||||
const [sessions, selectedIndex, selectSession, removeSession] = useChatStore(
|
||||
(state) => [
|
||||
state.sessions,
|
||||
state.currentSessionIndex,
|
||||
state.selectSession,
|
||||
state.removeSession,
|
||||
],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={styles["chat-list"]}>
|
||||
|
@ -171,7 +171,6 @@ export function ChatList() {
|
|||
selected={i === selectedIndex}
|
||||
onClick={() => selectSession(i)}
|
||||
onDelete={() => removeSession(i)}
|
||||
onEdit={(title: string) => editDialogTitle(i, title)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
|
|
@ -188,13 +188,13 @@ interface ChatStore {
|
|||
removeSession: (index: number) => void;
|
||||
selectSession: (index: number) => void;
|
||||
newSession: () => void;
|
||||
updateSessionTitle: (index: number, title: string) => void;
|
||||
currentSession: () => ChatSession;
|
||||
onNewMessage: (message: Message) => void;
|
||||
onUserInput: (content: string) => Promise<void>;
|
||||
summarizeSession: () => void;
|
||||
updateStat: (message: Message) => void;
|
||||
updateCurrentSession: (updater: (session: ChatSession) => void) => void;
|
||||
updateTitle: (title: string) => void;
|
||||
updateMessage: (
|
||||
sessionIndex: number,
|
||||
messageIndex: number,
|
||||
|
@ -269,17 +269,6 @@ export const useChatStore = create<ChatStore>()(
|
|||
});
|
||||
},
|
||||
|
||||
updateSessionTitle(index: number, title: string) {
|
||||
set((state) => {
|
||||
const sessions = state.sessions;
|
||||
sessions[index].topic = title;
|
||||
|
||||
return {
|
||||
sessions,
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
newSession() {
|
||||
set((state) => ({
|
||||
currentSessionIndex: 0,
|
||||
|
@ -408,6 +397,10 @@ export const useChatStore = create<ChatStore>()(
|
|||
set(() => ({ sessions }));
|
||||
},
|
||||
|
||||
updateTitle(title: string) {
|
||||
get().updateCurrentSession((session) => (session.topic = title));
|
||||
},
|
||||
|
||||
summarizeSession() {
|
||||
const session = get().currentSession();
|
||||
|
||||
|
|
Loading…
Reference in New Issue