mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 08:12:00 +02:00
feat: Add SearchBar component to Nav (#760)
* feat: Add SearchBar component to Nav This commit adds the SearchBar component to the navigation bar in order to enable search functionality. Now users can easily search for specific items within the navigation. * Refactor Nav and SearchBar components The commit refactors the Nav component by moving the SearchBar component within the Nav component. This change ensures that the SearchBar is rendered only when the isSearchEnabled condition is true. In addition, the commit also modifies the styling of the SearchBar component by adding rounded corners and border to enhance the visual appearance. * Update gitignore * C Refactor search bar styles This commit refactors the styles of the search bar component in the Nav component. The border color and hover background color have been modified to improve the visual appearance. * Fix margin * Rename Logout.jsx to Logout.tsx and update import statements accordingly. Replace the use of Recoil and store with useLocalize hook for localization. Update the usage of localize function by removing the lang parameter.
This commit is contained in:
parent
1f5a79f073
commit
173b8ce2da
6 changed files with 13 additions and 27 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -71,6 +71,7 @@ junit.xml
|
||||||
|
|
||||||
# meilisearch
|
# meilisearch
|
||||||
meilisearch
|
meilisearch
|
||||||
|
meilisearch.exe
|
||||||
data.ms/*
|
data.ms/*
|
||||||
auth.json
|
auth.json
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
import { forwardRef } from 'react';
|
import { forwardRef } from 'react';
|
||||||
import { LogOutIcon } from '../svg';
|
import { LogOutIcon } from '../svg';
|
||||||
import { useAuthContext } from '~/hooks/AuthContext';
|
import { useAuthContext } from '~/hooks/AuthContext';
|
||||||
import { useRecoilValue } from 'recoil';
|
import { useLocalize } from '~/hooks';
|
||||||
import store from '~/store';
|
|
||||||
import { localize } from '~/localization/Translation';
|
|
||||||
|
|
||||||
const Logout = forwardRef(() => {
|
const Logout = forwardRef(() => {
|
||||||
const { user, logout } = useAuthContext();
|
const { logout } = useAuthContext();
|
||||||
const lang = useRecoilValue(store.lang);
|
const localize = useLocalize();
|
||||||
|
|
||||||
const handleLogout = () => {
|
const handleLogout = () => {
|
||||||
logout();
|
logout();
|
||||||
|
@ -20,8 +18,7 @@ const Logout = forwardRef(() => {
|
||||||
onClick={handleLogout}
|
onClick={handleLogout}
|
||||||
>
|
>
|
||||||
<LogOutIcon />
|
<LogOutIcon />
|
||||||
{user?.username || localize(lang, 'com_nav_user')}
|
{localize('com_nav_log_out')}
|
||||||
<small>{localize(lang, 'com_nav_log_out')}</small>
|
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
});
|
});
|
|
@ -7,6 +7,7 @@ import {
|
||||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { useRecoilValue, useSetRecoilState } from 'recoil';
|
import { useRecoilValue, useSetRecoilState } from 'recoil';
|
||||||
import NewChat from './NewChat';
|
import NewChat from './NewChat';
|
||||||
|
import SearchBar from './SearchBar';
|
||||||
import NavLinks from './NavLinks';
|
import NavLinks from './NavLinks';
|
||||||
import { Panel, Spinner } from '~/components';
|
import { Panel, Spinner } from '~/components';
|
||||||
import { Conversations, Pages } from '../Conversations';
|
import { Conversations, Pages } from '../Conversations';
|
||||||
|
@ -166,7 +167,7 @@ export default function Nav({ navVisible, setNavVisible }) {
|
||||||
<div className="flex h-full min-h-0 flex-col ">
|
<div className="flex h-full min-h-0 flex-col ">
|
||||||
<div className="scrollbar-trigger relative flex h-full w-full flex-1 items-start border-white/20">
|
<div className="scrollbar-trigger relative flex h-full w-full flex-1 items-start border-white/20">
|
||||||
<nav className="relative flex h-full flex-1 flex-col space-y-1 p-2">
|
<nav className="relative flex h-full flex-1 flex-col space-y-1 p-2">
|
||||||
<div className="mb-2 flex h-11 flex-row">
|
<div className="mb-1 flex h-11 flex-row">
|
||||||
<NewChat />
|
<NewChat />
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
@ -179,6 +180,7 @@ export default function Nav({ navVisible, setNavVisible }) {
|
||||||
<Panel open={false} />
|
<Panel open={false} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
{isSearchEnabled && <SearchBar clearSearch={clearSearch} />}
|
||||||
<div
|
<div
|
||||||
className={`flex-1 flex-col overflow-y-auto ${
|
className={`flex-1 flex-col overflow-y-auto ${
|
||||||
isHovering ? '' : 'scrollbar-transparent'
|
isHovering ? '' : 'scrollbar-transparent'
|
||||||
|
@ -202,7 +204,7 @@ export default function Nav({ navVisible, setNavVisible }) {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<NavLinks clearSearch={clearSearch} isSearchEnabled={isSearchEnabled} />
|
<NavLinks />
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,20 +2,19 @@ import { Download } from 'lucide-react';
|
||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
import { Fragment, useState } from 'react';
|
import { Fragment, useState } from 'react';
|
||||||
import { Menu, Transition } from '@headlessui/react';
|
import { Menu, Transition } from '@headlessui/react';
|
||||||
import SearchBar from './SearchBar';
|
|
||||||
import ClearConvos from './ClearConvos';
|
import ClearConvos from './ClearConvos';
|
||||||
import Settings from './Settings';
|
import Settings from './Settings';
|
||||||
import NavLink from './NavLink';
|
import NavLink from './NavLink';
|
||||||
import Logout from './Logout';
|
import Logout from './Logout';
|
||||||
import { ExportModel } from './ExportConversation';
|
import { ExportModel } from './ExportConversation';
|
||||||
import { LinkIcon, DotsIcon, GearIcon, TrashIcon } from '~/components';
|
import { LinkIcon, DotsIcon, GearIcon } from '~/components';
|
||||||
import { localize } from '~/localization/Translation';
|
import { localize } from '~/localization/Translation';
|
||||||
import { useAuthContext } from '~/hooks/AuthContext';
|
import { useAuthContext } from '~/hooks/AuthContext';
|
||||||
import { cn } from '~/utils/';
|
import { cn } from '~/utils/';
|
||||||
|
|
||||||
import store from '~/store';
|
import store from '~/store';
|
||||||
|
|
||||||
export default function NavLinks({ clearSearch, isSearchEnabled }) {
|
export default function NavLinks() {
|
||||||
const [showExports, setShowExports] = useState(false);
|
const [showExports, setShowExports] = useState(false);
|
||||||
const [showClearConvos, setShowClearConvos] = useState(false);
|
const [showClearConvos, setShowClearConvos] = useState(false);
|
||||||
const [showSettings, setShowSettings] = useState(false);
|
const [showSettings, setShowSettings] = useState(false);
|
||||||
|
@ -76,11 +75,6 @@ export default function NavLinks({ clearSearch, isSearchEnabled }) {
|
||||||
leaveTo="transform opacity-0 scale-95"
|
leaveTo="transform opacity-0 scale-95"
|
||||||
>
|
>
|
||||||
<Menu.Items className="absolute bottom-full left-0 z-20 mb-2 w-full translate-y-0 overflow-hidden rounded-md bg-[#050509] py-1.5 opacity-100 outline-none">
|
<Menu.Items className="absolute bottom-full left-0 z-20 mb-2 w-full translate-y-0 overflow-hidden rounded-md bg-[#050509] py-1.5 opacity-100 outline-none">
|
||||||
{isSearchEnabled && (
|
|
||||||
<Menu.Item>
|
|
||||||
<SearchBar clearSearch={clearSearch} />
|
|
||||||
</Menu.Item>
|
|
||||||
)}
|
|
||||||
<Menu.Item as="div">
|
<Menu.Item as="div">
|
||||||
<NavLink
|
<NavLink
|
||||||
className={cn(
|
className={cn(
|
||||||
|
@ -93,14 +87,6 @@ export default function NavLinks({ clearSearch, isSearchEnabled }) {
|
||||||
/>
|
/>
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
<div className="my-1.5 h-px bg-white/20" role="none" />
|
<div className="my-1.5 h-px bg-white/20" role="none" />
|
||||||
<Menu.Item as="div">
|
|
||||||
<NavLink
|
|
||||||
className="flex w-full cursor-pointer items-center gap-3 rounded-none px-3 py-3 text-sm text-white transition-colors duration-200 hover:bg-gray-700"
|
|
||||||
svg={() => <TrashIcon />}
|
|
||||||
text={localize(lang, 'com_nav_clear_conversation')}
|
|
||||||
clickHandler={() => setShowClearConvos(true)}
|
|
||||||
/>
|
|
||||||
</Menu.Item>
|
|
||||||
<Menu.Item as="div">
|
<Menu.Item as="div">
|
||||||
<NavLink
|
<NavLink
|
||||||
className="flex w-full cursor-pointer items-center gap-3 rounded-none px-3 py-3 text-sm text-white transition-colors duration-200 hover:bg-gray-700"
|
className="flex w-full cursor-pointer items-center gap-3 rounded-none px-3 py-3 text-sm text-white transition-colors duration-200 hover:bg-gray-700"
|
||||||
|
|
|
@ -16,7 +16,7 @@ export default function NewChat() {
|
||||||
return (
|
return (
|
||||||
<a
|
<a
|
||||||
onClick={clickHandler}
|
onClick={clickHandler}
|
||||||
className="mb-2 flex h-11 flex-shrink-0 flex-grow cursor-pointer items-center gap-3 rounded-md border border-white/20 px-3 py-3 text-sm text-white transition-colors duration-200 hover:bg-gray-500/10"
|
className="flex h-11 flex-shrink-0 flex-grow cursor-pointer items-center gap-3 rounded-md border border-white/20 px-3 py-3 text-sm text-white transition-colors duration-200 hover:bg-gray-500/10"
|
||||||
>
|
>
|
||||||
<svg
|
<svg
|
||||||
stroke="currentColor"
|
stroke="currentColor"
|
||||||
|
|
|
@ -35,7 +35,7 @@ const SearchBar = forwardRef((props, ref) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className="relative flex w-full cursor-pointer items-center gap-3 px-3 py-3 text-sm text-white transition-colors duration-200 hover:bg-gray-700"
|
className="relative flex w-full cursor-pointer items-center gap-3 rounded-md border border-white/20 px-3 py-3 text-sm text-white transition-colors duration-200 hover:bg-gray-500/10"
|
||||||
>
|
>
|
||||||
{<Search className="absolute left-3 h-4 w-4" />}
|
{<Search className="absolute left-3 h-4 w-4" />}
|
||||||
<input
|
<input
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue