mirror of
https://github.com/NovaOSS/nova-betterchat.git
synced 2024-11-25 19:33:59 +01:00
optimise ChatHistoryList
This commit is contained in:
parent
5e1745fe0c
commit
f58382137d
|
@ -1,5 +1,6 @@
|
|||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import useStore from '@store/store';
|
||||
import { shallow } from 'zustand/shallow';
|
||||
|
||||
import ChatIcon from '@icon/ChatIcon';
|
||||
import EditIcon from '@icon/EditIcon';
|
||||
|
@ -11,16 +12,19 @@ import useInitialiseNewChat from '@hooks/useInitialiseNewChat';
|
|||
|
||||
const ChatHistoryList = () => {
|
||||
const setCurrentChatIndex = useStore((state) => state.setCurrentChatIndex);
|
||||
const chats = useStore((state) => state.chats);
|
||||
const chatTitles = useStore(
|
||||
(state) => state.chats?.map((chat) => chat.title),
|
||||
shallow
|
||||
);
|
||||
|
||||
return (
|
||||
<div className='flex-col flex-1 overflow-y-auto border-b border-white/20'>
|
||||
<div className='flex flex-col gap-2 text-gray-100 text-sm'>
|
||||
{chats &&
|
||||
chats.map((chat, index) => (
|
||||
{chatTitles &&
|
||||
chatTitles.map((title, index) => (
|
||||
<ChatHistory
|
||||
title={chat.title}
|
||||
key={`${chat.title}-${index}`}
|
||||
title={title}
|
||||
key={`${title}-${index}`}
|
||||
chatIndex={index}
|
||||
onClick={() => {
|
||||
setCurrentChatIndex(index);
|
||||
|
|
|
@ -142,8 +142,6 @@ const useSubmit = () => {
|
|||
updatedChats[currentChatIndex].title = title;
|
||||
updatedChats[currentChatIndex].titleSet = true;
|
||||
setChats(updatedChats);
|
||||
console.log(message);
|
||||
console.log(title);
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
const err = (e as Error).message;
|
||||
|
|
Loading…
Reference in a new issue