Skip to content

Commit fe391e3

Browse files
committed
fix: update get array value
1 parent ad44ae8 commit fe391e3

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/chat/content/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ const Content = forwardRef<IContentRef, IContentProps>(function (
5151
};
5252

5353
const dataValid = !!(Array.isArray(data) && data.length);
54-
const lastMessage = dataValid ? data.at(-1)?.messages?.at(-1) : undefined;
54+
const lastPrompt = data[data.length - 1];
55+
const lastMessage = dataValid
56+
? lastPrompt.messages?.[lastPrompt.messages.length - 1]
57+
: undefined;
5558

5659
useLayoutEffect(() => {
5760
const handleScroll = () => {

src/chat/group/Item/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export default function Item({
3939
onDelete?.(conversation);
4040
};
4141
const handleSelect = (conversation: ConversationProperties) => {
42-
console.log(conversation.id, selectId);
4342
if (conversation.id === selectId || edit) {
4443
return;
4544
}

src/chat/useChat.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,19 @@ export default function useChat<
212212

213213
// ================================== Global ==================================
214214
function _isProcessing() {
215-
const last = state.current?.prompts.at(-1)?.messages?.at(-1);
215+
const lastPrompt = state.current?.prompts?.[state.current?.prompts.length - 1];
216+
const last = lastPrompt?.messages?.[lastPrompt.messages.length - 1];
216217
if (!last) return false;
217218
return last.status === MessageStatus.PENDING || last.status === MessageStatus.GENERATING;
218219
}
219220

220221
async function _saveViewState() {
221-
const prompt = state.current?.prompts.at(-1);
222-
const message = prompt?.messages?.at(-1);
222+
const lastPrompt = state.current?.prompts?.[state.current?.prompts.length - 1];
223+
const message = lastPrompt?.messages?.[lastPrompt.messages.length - 1];
223224
if (message?.status === MessageStatus.GENERATING) {
224225
await typing.close(true);
225226
if (closing.current) {
226-
_updateMessage(prompt!.id, message.id, { status: MessageStatus.DONE });
227+
_updateMessage(lastPrompt!.id, message.id, { status: MessageStatus.DONE });
227228
}
228229
} else {
229230
typing.stop();
@@ -236,8 +237,10 @@ export default function useChat<
236237
closing.current = false;
237238
if (_isProcessing()) {
238239
const conversation = _getConversation();
239-
const prompt = conversation?.prompts.at(-1);
240-
const message = prompt?.messages.at(-1);
240+
const prompt = conversation?.prompts?.[conversation?.prompts.length - 1];
241+
const message = prompt?.messages?.[prompt.messages.length - 1];
242+
// 理论上这里不会出现没有 prompt 或 message 的情况
243+
/* istanbul ignore next */
241244
if (!prompt || !message) return state.current;
242245
typing.start(message.content);
243246
typingIds.current = { promptId: prompt.id, messageId: message.id };

0 commit comments

Comments
 (0)