mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
🔍 feat: Show Messages from Search Result (#2699)
* refactor(Nav): delegate Search-specific variables/hooks to SearchContext * fix: safely determine firstTodayConvoId if convo is undefined * chore: remove empty line * feat: initial render of search messages * feat: SearchButtons * update Ko.ts * update localizations with new key phrases * chore: localization comparisons * fix: clear conversation state on searchQuery navigation * style: search messages view styling * refactor(Convo): consolidate logic to navigateWithLastTools from useNavigateToConvo * fix(SearchButtons): styling and correct navigation logic * fix(SearchBar): invalidate all message queries and invoke `clearText` if onChange value is empty * refactor(NewChat): consolidate new chat button logic to NewChatButtonIcon * chore: localizations for Nav date groups * chore: update comparisons * fix: early return from sendRequest to avoid quick searchQuery reset * style: Link Icon * chore: bump tiktoken, use o200k_base for gpt-4o
This commit is contained in:
parent
638ac5bba6
commit
e42709bd1f
36 changed files with 2742 additions and 234 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import { useParams } from 'react-router-dom';
|
||||
import { useRecoilValue, useSetRecoilState } from 'recoil';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { useCallback, useEffect, useState, useMemo, memo } from 'react';
|
||||
import type { ConversationListResponse } from 'librechat-data-provider';
|
||||
import {
|
||||
useMediaQuery,
|
||||
useAuthContext,
|
||||
|
|
@ -10,9 +9,10 @@ import {
|
|||
useNavScrolling,
|
||||
useConversations,
|
||||
} from '~/hooks';
|
||||
import { useSearchInfiniteQuery, useConversationsInfiniteQuery } from '~/data-provider';
|
||||
import { useConversationsInfiniteQuery } from '~/data-provider';
|
||||
import { TooltipProvider, Tooltip } from '~/components/ui';
|
||||
import { Conversations } from '~/components/Conversations';
|
||||
import { useSearchContext } from '~/Providers';
|
||||
import { Spinner } from '~/components/svg';
|
||||
import SearchBar from './SearchBar';
|
||||
import NavToggle from './NavToggle';
|
||||
|
|
@ -47,26 +47,18 @@ const Nav = ({ navVisible, setNavVisible }) => {
|
|||
}
|
||||
}, [isSmallScreen]);
|
||||
|
||||
const [pageNumber, setPageNumber] = useState(1);
|
||||
const { newConversation } = useConversation();
|
||||
const [showLoading, setShowLoading] = useState(false);
|
||||
|
||||
const searchQuery = useRecoilValue(store.searchQuery);
|
||||
const isSearchEnabled = useRecoilValue(store.isSearchEnabled);
|
||||
const { newConversation, searchPlaceholderConversation } = useConversation();
|
||||
|
||||
const { refreshConversations } = useConversations();
|
||||
const setSearchResultMessages = useSetRecoilState(store.searchResultMessages);
|
||||
const { pageNumber, searchQuery, setPageNumber, searchQueryRes } = useSearchContext();
|
||||
|
||||
const { data, fetchNextPage, hasNextPage, isFetchingNextPage } = useConversationsInfiniteQuery(
|
||||
{ pageNumber: pageNumber.toString(), isArchived: false },
|
||||
{ enabled: isAuthenticated },
|
||||
);
|
||||
|
||||
const searchQueryRes = useSearchInfiniteQuery(
|
||||
{ pageNumber: pageNumber.toString(), searchQuery: searchQuery, isArchived: false },
|
||||
{ enabled: isAuthenticated && !!searchQuery.length },
|
||||
);
|
||||
|
||||
const { containerRef, moveToTop } = useNavScrolling({
|
||||
setShowLoading,
|
||||
hasNextPage: searchQuery ? searchQueryRes.hasNextPage : hasNextPage,
|
||||
|
|
@ -81,21 +73,6 @@ const Nav = ({ navVisible, setNavVisible }) => {
|
|||
[data, searchQuery, searchQueryRes?.data],
|
||||
);
|
||||
|
||||
const onSearchSuccess = useCallback(({ data }: { data: ConversationListResponse }) => {
|
||||
const res = data;
|
||||
searchPlaceholderConversation();
|
||||
setSearchResultMessages(res.messages);
|
||||
/* disabled due recoil methods not recognized as state setters */
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []); // Empty dependency array
|
||||
|
||||
useEffect(() => {
|
||||
//we use isInitialLoading here instead of isLoading because query is disabled by default
|
||||
if (searchQueryRes.data) {
|
||||
onSearchSuccess({ data: searchQueryRes.data.pages[0] });
|
||||
}
|
||||
}, [searchQueryRes.data, searchQueryRes.isInitialLoading, onSearchSuccess]);
|
||||
|
||||
const clearSearch = () => {
|
||||
setPageNumber(1);
|
||||
refreshConversations();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue