mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 08:33:20 +00:00
fix: issue #157
This commit is contained in:
@@ -7,9 +7,7 @@ import DocumentationDark from './assets/documentation-dark.svg';
|
|||||||
import Discord from './assets/discord.svg';
|
import Discord from './assets/discord.svg';
|
||||||
import DiscordDark from './assets/discord-dark.svg';
|
import DiscordDark from './assets/discord-dark.svg';
|
||||||
|
|
||||||
import Arrow2 from './assets/dropdown-arrow.svg';
|
|
||||||
import Expand from './assets/expand.svg';
|
import Expand from './assets/expand.svg';
|
||||||
import Trash from './assets/trash.svg';
|
|
||||||
import Github from './assets/github.svg';
|
import Github from './assets/github.svg';
|
||||||
import GithubDark from './assets/github-dark.svg';
|
import GithubDark from './assets/github-dark.svg';
|
||||||
import Hamburger from './assets/hamburger.svg';
|
import Hamburger from './assets/hamburger.svg';
|
||||||
@@ -42,27 +40,23 @@ import { Doc, getConversations } from './preferences/preferenceApi';
|
|||||||
import SelectDocsModal from './preferences/SelectDocsModal';
|
import SelectDocsModal from './preferences/SelectDocsModal';
|
||||||
import ConversationTile from './conversation/ConversationTile';
|
import ConversationTile from './conversation/ConversationTile';
|
||||||
import { useDarkTheme } from './hooks';
|
import { useDarkTheme } from './hooks';
|
||||||
|
import Dropdown from './components/Dropdown';
|
||||||
|
|
||||||
interface NavigationProps {
|
interface NavigationProps {
|
||||||
navOpen: boolean;
|
navOpen: boolean;
|
||||||
setNavOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
setNavOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
}
|
}
|
||||||
const NavImage: React.FC<{ Light: string, Dark: string }> = ({ Light, Dark }) => {
|
const NavImage: React.FC<{ Light: string; Dark: string }> = ({
|
||||||
|
Light,
|
||||||
|
Dark,
|
||||||
|
}) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<img
|
<img src={Dark} alt="icon" className="ml-2 hidden w-5 dark:block " />
|
||||||
src={Dark}
|
<img src={Light} alt="icon" className="ml-2 w-5 dark:hidden " />
|
||||||
alt="icon"
|
|
||||||
className="ml-2 w-5 hidden dark:block "
|
|
||||||
/>
|
|
||||||
<img
|
|
||||||
src={Light}
|
|
||||||
alt="icon"
|
|
||||||
className="ml-2 w-5 dark:hidden "
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
export default function Navigation({ navOpen, setNavOpen }: NavigationProps) {
|
export default function Navigation({ navOpen, setNavOpen }: NavigationProps) {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const docs = useSelector(selectSourceDocs);
|
const docs = useSelector(selectSourceDocs);
|
||||||
@@ -86,9 +80,6 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) {
|
|||||||
|
|
||||||
const navRef = useRef(null);
|
const navRef = useRef(null);
|
||||||
const apiHost = import.meta.env.VITE_API_HOST || 'https://docsapi.arc53.com';
|
const apiHost = import.meta.env.VITE_API_HOST || 'https://docsapi.arc53.com';
|
||||||
const embeddingsName =
|
|
||||||
import.meta.env.VITE_EMBEDDINGS_NAME ||
|
|
||||||
'huggingface_sentence-transformers/all-mpnet-base-v2';
|
|
||||||
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
@@ -203,15 +194,17 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) {
|
|||||||
<img
|
<img
|
||||||
src={Expand}
|
src={Expand}
|
||||||
alt="menu toggle"
|
alt="menu toggle"
|
||||||
className={`${!navOpen ? 'rotate-180' : 'rotate-0'
|
className={`${
|
||||||
|
!navOpen ? 'rotate-180' : 'rotate-0'
|
||||||
} m-auto transition-all duration-200`}
|
} m-auto transition-all duration-200`}
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
<div
|
<div
|
||||||
ref={navRef}
|
ref={navRef}
|
||||||
className={`${!navOpen && '-ml-96 md:-ml-[18rem]'
|
className={`${
|
||||||
} duration-20 fixed top-0 z-20 flex h-full w-72 flex-col border-r-[1px] border-b-0 dark:border-r-purple-taupe bg-white dark:bg-chinese-black transition-all dark:text-white`}
|
!navOpen && '-ml-96 md:-ml-[18rem]'
|
||||||
|
} duration-20 fixed top-0 z-20 flex h-full w-72 flex-col border-r-[1px] border-b-0 bg-white transition-all dark:border-r-purple-taupe dark:bg-chinese-black dark:text-white`}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={'visible mt-2 flex h-[6vh] w-full justify-between md:h-12'}
|
className={'visible mt-2 flex h-[6vh] w-full justify-between md:h-12'}
|
||||||
@@ -229,7 +222,8 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) {
|
|||||||
<img
|
<img
|
||||||
src={Expand}
|
src={Expand}
|
||||||
alt="menu toggle"
|
alt="menu toggle"
|
||||||
className={`${!navOpen ? 'rotate-180' : 'rotate-0'
|
className={`${
|
||||||
|
!navOpen ? 'rotate-180' : 'rotate-0'
|
||||||
} m-auto transition-all duration-200`}
|
} m-auto transition-all duration-200`}
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
@@ -245,8 +239,9 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) {
|
|||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
className={({ isActive }) =>
|
className={({ isActive }) =>
|
||||||
`${isActive ? 'bg-gray-3000 dark:bg-transparent' : ''
|
`${
|
||||||
} group sticky mx-4 mt-4 flex cursor-pointer gap-2.5 rounded-3xl border border-silver p-3 hover:border-rainy-gray dark:border-purple-taupe dark:text-white dark:hover:bg-transparent hover:bg-gray-3000`
|
isActive ? 'bg-gray-3000 dark:bg-transparent' : ''
|
||||||
|
} group sticky mx-4 mt-4 flex cursor-pointer gap-2.5 rounded-3xl border border-silver p-3 hover:border-rainy-gray hover:bg-gray-3000 dark:border-purple-taupe dark:text-white dark:hover:bg-transparent`
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
@@ -258,7 +253,7 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) {
|
|||||||
New Chat
|
New Chat
|
||||||
</p>
|
</p>
|
||||||
</NavLink>
|
</NavLink>
|
||||||
<div className="mb-auto h-[56vh] overflow-x-hidden dark:text-white overflow-y-scroll">
|
<div className="mb-auto h-[56vh] overflow-x-hidden overflow-y-scroll dark:text-white">
|
||||||
{conversations && (
|
{conversations && (
|
||||||
<div>
|
<div>
|
||||||
<p className="ml-6 mt-3 text-sm font-semibold">Chats</p>
|
<p className="ml-6 mt-3 text-sm font-semibold">Chats</p>
|
||||||
@@ -282,88 +277,44 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) {
|
|||||||
<div className="flex h-auto flex-col justify-end text-eerie-black dark:text-white">
|
<div className="flex h-auto flex-col justify-end text-eerie-black dark:text-white">
|
||||||
<div className="flex flex-col-reverse border-b-[1px] dark:border-b-purple-taupe">
|
<div className="flex flex-col-reverse border-b-[1px] dark:border-b-purple-taupe">
|
||||||
<div className="relative my-4 flex gap-2 px-2">
|
<div className="relative my-4 flex gap-2 px-2">
|
||||||
<div
|
<Dropdown
|
||||||
className="flex h-12 w-5/6 cursor-pointer justify-between rounded-3xl border-2 dark:border-chinese-silver bg-white dark:bg-chinese-black"
|
options={docs}
|
||||||
onClick={() => setIsDocsListOpen(!isDocsListOpen)}
|
selectedDocs={selectedDocs}
|
||||||
>
|
setSelectedDocs={setSelectedDocs}
|
||||||
{selectedDocs && (
|
isDocsListOpen={isDocsListOpen}
|
||||||
<p className="my-3 mx-4 overflow-hidden text-ellipsis whitespace-nowrap">
|
setIsDocsListOpen={setIsDocsListOpen}
|
||||||
{selectedDocs.name} {selectedDocs.version}
|
handleDeleteClick={handleDeleteClick}
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
<img
|
|
||||||
src={Arrow2}
|
|
||||||
alt="arrow"
|
|
||||||
className={`${!isDocsListOpen ? 'rotate-0' : 'rotate-180'
|
|
||||||
} ml-auto mr-3 w-3 transition-all`}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
<img
|
<img
|
||||||
className="mt-2 h-9 w-9 hover:cursor-pointer"
|
className="mt-2 h-9 w-9 hover:cursor-pointer"
|
||||||
src={UploadIcon}
|
src={UploadIcon}
|
||||||
onClick={() => setUploadModalState('ACTIVE')}
|
onClick={() => setUploadModalState('ACTIVE')}
|
||||||
></img>
|
></img>
|
||||||
{isDocsListOpen && (
|
|
||||||
<div className="absolute top-12 left-0 right-6 z-10 ml-2 mr-4 max-h-52 overflow-y-scroll bg-white dark:bg-chinese-black shadow-lg">
|
|
||||||
{docs ? (
|
|
||||||
docs.map((doc, index) => {
|
|
||||||
if (doc.model === embeddingsName) {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
key={index}
|
|
||||||
onClick={() => {
|
|
||||||
dispatch(setSelectedDocs(doc));
|
|
||||||
setIsDocsListOpen(false);
|
|
||||||
}}
|
|
||||||
className="flex h-10 w-full cursor-pointer items-center justify-between border-x-2 border-b-[1px] dark:border-purple-taupe hover:bg-gray-100 dark:hover:bg-purple-taupe"
|
|
||||||
>
|
|
||||||
<p className="ml-5 flex-1 overflow-hidden overflow-ellipsis whitespace-nowrap py-3">
|
|
||||||
{doc.name} {doc.version}
|
|
||||||
</p>
|
|
||||||
{doc.location === 'local' && (
|
|
||||||
<img
|
|
||||||
src={Trash}
|
|
||||||
alt="Delete"
|
|
||||||
className="mr-4 h-4 w-4 cursor-pointer hover:opacity-50"
|
|
||||||
id={`img-${index}`}
|
|
||||||
onClick={(event) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
handleDeleteClick(index, doc);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
) : (
|
|
||||||
<div className="h-10 w-full cursor-pointer border-b-[1px] dark:border-b-purple-taupe hover:bg-gray-100">
|
|
||||||
<p className="ml-5 py-3">No default documentation.</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
<p className="ml-6 mt-3 text-sm font-semibold">Source Docs</p>
|
<p className="ml-6 mt-3 text-sm font-semibold">Source Docs</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-2 border-b-[1px] dark:border-b-purple-taupe py-2">
|
<div className="flex flex-col gap-2 border-b-[1px] py-2 dark:border-b-purple-taupe">
|
||||||
<NavLink
|
<NavLink
|
||||||
to="/settings"
|
to="/settings"
|
||||||
className={({ isActive }) =>
|
className={({ isActive }) =>
|
||||||
`my-auto mx-4 flex h-9 cursor-pointer gap-4 rounded-3xl hover:bg-gray-100 dark:hover:bg-purple-taupe ${isActive ? 'bg-gray-3000 dark:bg-transparent' : ''
|
`my-auto mx-4 flex h-9 cursor-pointer gap-4 rounded-3xl hover:bg-gray-100 dark:hover:bg-purple-taupe ${
|
||||||
|
isActive ? 'bg-gray-3000 dark:bg-transparent' : ''
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<NavImage Light={SettingGear} Dark={SettingGearDark} />
|
<NavImage Light={SettingGear} Dark={SettingGearDark} />
|
||||||
<p className="my-auto text-sm text-eerie-black dark:text-white">Settings</p>
|
<p className="my-auto text-sm text-eerie-black dark:text-white">
|
||||||
|
Settings
|
||||||
|
</p>
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-2 border-b-[1.5px] dark:border-b-purple-taupe py-2">
|
<div className="flex flex-col gap-2 border-b-[1.5px] py-2 dark:border-b-purple-taupe">
|
||||||
<NavLink
|
<NavLink
|
||||||
to="/about"
|
to="/about"
|
||||||
className={({ isActive }) =>
|
className={({ isActive }) =>
|
||||||
`my-auto mx-4 flex h-9 cursor-pointer gap-4 rounded-3xl hover:bg-gray-100 dark:hover:bg-purple-taupe ${isActive ? 'bg-gray-3000 dark:bg-purple-taupe' : ''
|
`my-auto mx-4 flex h-9 cursor-pointer gap-4 rounded-3xl hover:bg-gray-100 dark:hover:bg-purple-taupe ${
|
||||||
|
isActive ? 'bg-gray-3000 dark:bg-purple-taupe' : ''
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -388,31 +339,31 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) {
|
|||||||
>
|
>
|
||||||
<NavImage Light={Discord} Dark={DiscordDark} />
|
<NavImage Light={Discord} Dark={DiscordDark} />
|
||||||
{/* <img src={isDarkTheme ? DiscordDark : Discord} alt="discord-link" className="ml-2 w-5" /> */}
|
{/* <img src={isDarkTheme ? DiscordDark : Discord} alt="discord-link" className="ml-2 w-5" /> */}
|
||||||
<p className="my-auto text-sm">
|
<p className="my-auto text-sm">Visit our Discord</p>
|
||||||
Visit our Discord
|
|
||||||
</p>
|
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a
|
<a
|
||||||
href="https://github.com/arc53/DocsGPT"
|
href="https://github.com/arc53/DocsGPT"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noreferrer"
|
rel="noreferrer"
|
||||||
className="mt-auto mx-4 flex h-9 cursor-pointer gap-4 rounded-3xl hover:bg-gray-100 dark:hover:bg-purple-taupe"
|
className="mx-4 mt-auto flex h-9 cursor-pointer gap-4 rounded-3xl hover:bg-gray-100 dark:hover:bg-purple-taupe"
|
||||||
>
|
>
|
||||||
<NavImage Light={Github} Dark={GithubDark} />
|
<NavImage Light={Github} Dark={GithubDark} />
|
||||||
<p className="my-auto text-sm">
|
<p className="my-auto text-sm">Visit our Github</p>
|
||||||
Visit our Github
|
|
||||||
</p>
|
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="fixed z-10 h-16 w-full border-b-2 dark:border-b-purple-taupe bg-gray-50 dark:bg-chinese-black md:hidden">
|
<div className="fixed z-10 h-16 w-full border-b-2 bg-gray-50 dark:border-b-purple-taupe dark:bg-chinese-black md:hidden">
|
||||||
<button
|
<button
|
||||||
className="mt-5 ml-6 h-6 w-6 md:hidden"
|
className="mt-5 ml-6 h-6 w-6 md:hidden"
|
||||||
onClick={() => setNavOpen(true)}
|
onClick={() => setNavOpen(true)}
|
||||||
>
|
>
|
||||||
<img src={isDarkTheme ? HamburgerDark : Hamburger} alt="menu toggle" className="w-7" />
|
<img
|
||||||
|
src={isDarkTheme ? HamburgerDark : Hamburger}
|
||||||
|
alt="menu toggle"
|
||||||
|
className="w-7"
|
||||||
|
/>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<SelectDocsModal
|
<SelectDocsModal
|
||||||
|
|||||||
102
frontend/src/components/Dropdown.tsx
Normal file
102
frontend/src/components/Dropdown.tsx
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
import Trash from '../assets/trash.svg';
|
||||||
|
import Arrow2 from '../assets/dropdown-arrow.svg';
|
||||||
|
import { Doc } from '../preferences/preferenceApi';
|
||||||
|
import { useDispatch } from 'react-redux';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
options: Doc[] | null;
|
||||||
|
selectedDocs: Doc | null;
|
||||||
|
setSelectedDocs: any;
|
||||||
|
isDocsListOpen: boolean;
|
||||||
|
setIsDocsListOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
|
handleDeleteClick: any;
|
||||||
|
};
|
||||||
|
|
||||||
|
function Dropdown({
|
||||||
|
options,
|
||||||
|
setSelectedDocs,
|
||||||
|
selectedDocs,
|
||||||
|
setIsDocsListOpen,
|
||||||
|
isDocsListOpen,
|
||||||
|
handleDeleteClick,
|
||||||
|
}: Props) {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const embeddingsName =
|
||||||
|
import.meta.env.VITE_EMBEDDINGS_NAME ||
|
||||||
|
'huggingface_sentence-transformers/all-mpnet-base-v2';
|
||||||
|
return (
|
||||||
|
<div className="relative w-5/6 rounded-3xl">
|
||||||
|
<button
|
||||||
|
onClick={() => setIsDocsListOpen(!isDocsListOpen)}
|
||||||
|
className={`flex w-full cursor-pointer items-center border-2 bg-white p-3 dark:border-chinese-silver dark:bg-transparent ${
|
||||||
|
isDocsListOpen ? 'rounded-t-3xl' : 'rounded-3xl'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<span className="ml-1 mr-2 flex-1 overflow-hidden text-ellipsis text-left dark:text-bright-gray">
|
||||||
|
<div className="flex flex-row gap-2">
|
||||||
|
<p className="max-w-3/4 truncate whitespace-nowrap">
|
||||||
|
{selectedDocs?.name}
|
||||||
|
</p>
|
||||||
|
<p className="flex flex-col items-center justify-center">
|
||||||
|
{selectedDocs?.version}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</span>
|
||||||
|
<img
|
||||||
|
src={Arrow2}
|
||||||
|
alt="arrow"
|
||||||
|
className={`transform ${
|
||||||
|
isDocsListOpen ? 'rotate-180' : 'rotate-0'
|
||||||
|
} h-3 w-3 transition-transform`}
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
{isDocsListOpen && (
|
||||||
|
<div className="absolute left-0 right-0 z-50 -mt-1 max-h-40 overflow-y-auto rounded-b-xl border-2 bg-white shadow-lg dark:border-chinese-silver dark:bg-dark-charcoal">
|
||||||
|
{options ? (
|
||||||
|
options.map((option: any, index: number) => {
|
||||||
|
if (option.model !== embeddingsName) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className="flex cursor-pointer items-center justify-between hover:bg-gray-100 dark:text-bright-gray dark:hover:bg-purple-taupe"
|
||||||
|
onClick={() => {
|
||||||
|
dispatch(setSelectedDocs(option));
|
||||||
|
setIsDocsListOpen(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
onClick={() => {
|
||||||
|
setIsDocsListOpen(false);
|
||||||
|
}}
|
||||||
|
className="ml-4 flex-1 overflow-hidden overflow-ellipsis whitespace-nowrap py-3"
|
||||||
|
>
|
||||||
|
{option.name}
|
||||||
|
</span>
|
||||||
|
{option.location === 'local' && (
|
||||||
|
<img
|
||||||
|
src={Trash}
|
||||||
|
alt="Delete"
|
||||||
|
className="mr-4 h-4 w-4 cursor-pointer hover:opacity-50"
|
||||||
|
id={`img-${index}`}
|
||||||
|
onClick={(event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
handleDeleteClick(index, option);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
) : (
|
||||||
|
<div className="h-10 w-full cursor-pointer border-b-[1px] hover:bg-gray-100 dark:border-b-purple-taupe">
|
||||||
|
<p className="ml-5 py-3">No default documentation.</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Dropdown;
|
||||||
Reference in New Issue
Block a user