fix: sort non filtered history as well (#2)

dough don't push something wihtout testing :/
This commit is contained in:
Niklas 2023-03-24 14:49:40 +01:00
parent 172785338c
commit 4810f7425b
1 changed files with 5 additions and 4 deletions

View File

@ -12,13 +12,14 @@ export const ChatHistoryView: FC<{}> = props => {
const elementRef = useRef<HTMLDivElement>(null);
const filteredChatHistory = useMemo(() => {
if (searchText.length === 0) return chatHistory;
const sortedChatHistory = chatHistory.sort((a, b) => b.id - a.id);
if (searchText.length === 0) return sortedChatHistory;
let text = searchText.toLowerCase();
return chatHistory
.filter(entry => (entry.message && entry.message.toLowerCase().includes(text)) || (entry.name && entry.name.toLowerCase().includes(text)))
.sort((a, b) => b.id - a.id);
return sortedChatHistory
.filter(entry => (entry.message && entry.message.toLowerCase().includes(text)) || (entry.name && entry.name.toLowerCase().includes(text)));
}, [chatHistory, searchText]);
useEffect(() => {