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