Skip to content

Commit

Permalink
studio navigation using left sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiya1155 committed Jan 18, 2024
1 parent 47b51c5 commit 714a37d
Show file tree
Hide file tree
Showing 31 changed files with 532 additions and 323 deletions.
36 changes: 35 additions & 1 deletion client/src/Project/CurrentTabContent/Header/TabButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ type Props = TabType & {
tokenRange?: string;
focusedPanel: 'left' | 'right';
isTemp?: boolean;
studioId?: string;
initialRanges?: [number, number][];
isFileInContext?: boolean;
conversationId?: string;
initialQuery?: string;
};

const closeTabShortcut = ['cmd', 'W'];
Expand All @@ -58,6 +63,11 @@ const TabButton = ({
tokenRange,
focusedPanel,
isTemp,
studioId,
initialRanges,
isFileInContext,
conversationId,
initialQuery,
}: Props) => {
const { t } = useTranslation();
const { closeTab, setActiveLeftTab, setActiveRightTab, setFocusedPanel } =
Expand Down Expand Up @@ -140,6 +150,11 @@ const TabButton = ({
branch,
scrollToLine,
tokenRange,
studioId,
initialRanges,
isFileInContext,
conversationId,
initialQuery,
},
side,
};
Expand Down Expand Up @@ -170,9 +185,28 @@ const TabButton = ({
branch,
scrollToLine,
tokenRange,
studioId,
initialRanges,
isFileInContext,
conversationId,
initialQuery,
});
setFocusedPanel(side);
}, [path, repoRef, tabKey, side, branch, scrollToLine, tokenRange, title]);
}, [
path,
repoRef,
tabKey,
side,
branch,
scrollToLine,
tokenRange,
title,
studioId,
initialRanges,
isFileInContext,
conversationId,
initialQuery,
]);

return (
<a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Props = {
templatesRef?: React.MutableRefObject<HTMLButtonElement | null>;
isTokenLimitExceeded: boolean;
isLast: boolean;
isActiveTab: boolean;
side: 'left' | 'right';
templates?: StudioTemplateType[];
setIsDropdownShown: (b: boolean) => void;
Expand All @@ -55,6 +56,7 @@ const ConversationInput = ({
templates,
setIsDropdownShown,
templatesRef,
isActiveTab,
}: Props) => {
const { t } = useTranslation();
const { envConfig } = useContext(EnvContext);
Expand All @@ -65,9 +67,11 @@ const ConversationInput = ({

const handleChange = useCallback(
(e: ChangeEvent<HTMLTextAreaElement>) => {
onMessageChange(e.target.value, i);
if (isActiveTab) {
onMessageChange(e.target.value, i);
}
},
[i, onMessageChange],
[i, onMessageChange, isActiveTab],
);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ const Conversation = ({
isLast={i === studioData.conversation.length - 1}
side={side}
templates={templates}
isActiveTab={isActiveTab}
setIsDropdownShown={setIsDropdownShown}
/>
))}
Expand Down Expand Up @@ -198,6 +199,7 @@ const Conversation = ({
templates={templates}
setIsDropdownShown={setIsDropdownShown}
templatesRef={templatesRef}
isActiveTab={isActiveTab}
/>
)}
</ScrollToBottom>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { memo, useCallback, useContext } from 'react';
import { useTranslation } from 'react-i18next';
import DropdownSection from '../../../components/Dropdown/Section';
import SectionItem from '../../../components/Dropdown/Section/SectionItem';
import { TrashCanIcon } from '../../../icons';
import { deleteConversation } from '../../../services/api';
import { ProjectContext } from '../../../context/projectContext';
import DropdownSection from '../../../../components/Dropdown/Section';
import SectionItem from '../../../../components/Dropdown/Section/SectionItem';
import { TrashCanIcon } from '../../../../icons';
import { deleteConversation } from '../../../../services/api';
import { ProjectContext } from '../../../../context/projectContext';

type Props = {};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import { memo, useCallback, useContext } from 'react';
import { ConversationShortType } from '../../../types/api';
import { TabsContext } from '../../../context/tabsContext';
import { TabTypesEnum } from '../../../types/general';
import { ConversationShortType } from '../../../../types/api';
import { TabsContext } from '../../../../context/tabsContext';
import { TabTypesEnum } from '../../../../types/general';
import { useEnterKey } from '../../../../hooks/useEnterKey';

type Props = ConversationShortType & {
index: string;
focusedIndex: string;
isLeftSidebarFocused: boolean;
};

const ConversationEntry = ({ title, id, index, focusedIndex }: Props) => {
const ConversationEntry = ({
title,
id,
index,
focusedIndex,
isLeftSidebarFocused,
}: Props) => {
const { openNewTab } = useContext(TabsContext.Handlers);

const handleClick = useCallback(() => {
openNewTab({ type: TabTypesEnum.CHAT, conversationId: id, title });
}, [openNewTab, id, title]);

useEnterKey(handleClick, focusedIndex !== index || !isLeftSidebarFocused);

return (
<a
href="#"
Expand All @@ -24,7 +34,7 @@ const ConversationEntry = ({ title, id, index, focusedIndex }: Props) => {
? 'bg-bg-sub-hover text-label-title'
: 'text-label-base'
}
hover:bg-bg-base-hover hover:text-label-title active:bg-transparent pl-[2.625rem]`}
hover:bg-bg-base-hover hover:text-label-title active:bg-transparent pl-10.5`}
onClick={handleClick}
data-node-index={index}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
import React, {
Dispatch,
memo,
SetStateAction,
useCallback,
useEffect,
useRef,
MouseEvent,
useContext,
} from 'react';
import React, { Dispatch, memo, SetStateAction, useContext } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import Dropdown from '../../../components/Dropdown';
import Dropdown from '../../../../components/Dropdown';
import {
ArrowTriangleBottomIcon,
ChatBubblesIcon,
MoreHorizontalIcon,
} from '../../../icons';
import Button from '../../../components/Button';
import { ProjectContext } from '../../../context/projectContext';
} from '../../../../icons';
import Button from '../../../../components/Button';
import { ProjectContext } from '../../../../context/projectContext';
import { useNavPanel } from '../../../../hooks/useNavPanel';
import ConversationsDropdown from './ConversationsDropdown';
import ConversationEntry from './CoversationEntry';

type Props = {
setExpanded: Dispatch<SetStateAction<number>>;
setExpanded: Dispatch<SetStateAction<string>>;
isExpanded: boolean;
focusedIndex: string;
index: string;
Expand All @@ -37,27 +29,8 @@ const ConversationsNav = ({
}: Props) => {
const { t } = useTranslation();
const { project } = useContext(ProjectContext.Current);
const containerRef = useRef<HTMLDivElement>(null);

const toggleExpanded = useCallback(() => {
setExpanded((prev) => (prev === 0 ? -1 : 0));
}, []);

useEffect(() => {
if (isExpanded) {
// containerRef.current?.scrollIntoView({ block: 'nearest' });
}
}, [isExpanded]);

const noPropagate = useCallback((e?: MouseEvent) => {
e?.stopPropagation();
}, []);

useEffect(() => {
if (focusedIndex === index && containerRef.current) {
containerRef.current.scrollIntoView({ block: 'nearest' });
}
}, [focusedIndex, index]);
const { containerRef, toggleExpanded, noPropagate, isLeftSidebarFocused } =
useNavPanel(index, setExpanded, isExpanded, focusedIndex);

return (
<div className="select-none overflow-hidden w-full flex-shrink-0">
Expand Down Expand Up @@ -108,12 +81,13 @@ const ConversationsNav = ({
</span>
{isExpanded && (
<div className={'overflow-hidden'}>
{project?.conversations.map((c, ci) => (
{project?.conversations.map((c) => (
<ConversationEntry
key={c.id}
{...c}
index={`${index}-${ci}`}
index={`${index}-${c.id}`}
focusedIndex={focusedIndex}
isLeftSidebarFocused={isLeftSidebarFocused}
/>
))}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ import {
useEffect,
} from 'react';
import { useTranslation } from 'react-i18next';
import DropdownSection from '../../../components/Dropdown/Section';
import SectionItem from '../../../components/Dropdown/Section/SectionItem';
import DropdownSection from '../../../../components/Dropdown/Section';
import SectionItem from '../../../../components/Dropdown/Section/SectionItem';
import {
ArrowTriangleBottomIcon,
BranchIcon,
RefreshIcon,
TrashCanIcon,
} from '../../../icons';
} from '../../../../icons';
import {
changeRepoBranch,
indexRepoBranch,
removeRepoFromProject,
syncRepo,
} from '../../../services/api';
import { DeviceContext } from '../../../context/deviceContext';
import SpinLoaderContainer from '../../../components/Loaders/SpinnerLoader';
import SectionLabel from '../../../components/Dropdown/Section/SectionLabel';
import Button from '../../../components/Button';
import { ProjectContext } from '../../../context/projectContext';
import { PersonalQuotaContext } from '../../../context/personalQuotaContext';
import { RepoIndexingStatusType } from '../../../types/general';
import { RepositoriesContext } from '../../../context/repositoriesContext';
import { UIContext } from '../../../context/uiContext';
} from '../../../../services/api';
import { DeviceContext } from '../../../../context/deviceContext';
import SpinLoaderContainer from '../../../../components/Loaders/SpinnerLoader';
import SectionLabel from '../../../../components/Dropdown/Section/SectionLabel';
import Button from '../../../../components/Button';
import { ProjectContext } from '../../../../context/projectContext';
import { PersonalQuotaContext } from '../../../../context/personalQuotaContext';
import { RepoIndexingStatusType } from '../../../../types/general';
import { RepositoriesContext } from '../../../../context/repositoriesContext';
import { UIContext } from '../../../../context/uiContext';

type Props = {
repoRef: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import React, {
useRef,
useState,
} from 'react';
import { ChevronRightIcon, EyeCutIcon, FolderIcon } from '../../../icons';
import FileIcon from '../../../components/FileIcon';
import { DirectoryEntry } from '../../../types/api';
import { TabsContext } from '../../../context/tabsContext';
import { ChevronRightIcon, EyeCutIcon, FolderIcon } from '../../../../icons';
import FileIcon from '../../../../components/FileIcon';
import { DirectoryEntry } from '../../../../types/api';
import { TabsContext } from '../../../../context/tabsContext';
import {
RepoIndexingStatusType,
SyncStatus,
TabTypesEnum,
} from '../../../types/general';
import SpinLoaderContainer from '../../../components/Loaders/SpinnerLoader';
import { UIContext } from '../../../context/uiContext';
import useKeyboardNavigation from '../../../hooks/useKeyboardNavigation';
} from '../../../../types/general';
import SpinLoaderContainer from '../../../../components/Loaders/SpinnerLoader';
import { useEnterKey } from '../../../../hooks/useEnterKey';

type Props = {
name: string;
Expand All @@ -34,6 +33,7 @@ type Props = {
indexingData?: RepoIndexingStatusType;
focusedIndex: string;
index: string;
isLeftSidebarFocused: boolean;
};

const RepoEntry = ({
Expand All @@ -51,9 +51,9 @@ const RepoEntry = ({
indexingData,
focusedIndex,
index,
isLeftSidebarFocused,
}: Props) => {
const { openNewTab } = useContext(TabsContext.Handlers);
const { isLeftSidebarFocused } = useContext(UIContext.Focus);
const [isOpen, setOpen] = useState(
defaultOpen || (currentPath && currentPath.startsWith(fullPath)),
);
Expand Down Expand Up @@ -110,15 +110,7 @@ const RepoEntry = ({
}
}, [isDirectory, fullPath, openNewTab, repoRef, branch]);

const handleKeyEvent = useCallback(
(e: KeyboardEvent) => {
if (e.key === 'Enter') {
handleClick();
}
},
[handleClick],
);
useKeyboardNavigation(handleKeyEvent, focusedIndex !== index);
useEnterKey(handleClick, focusedIndex !== index || !isLeftSidebarFocused);

useEffect(() => {
if (focusedIndex === index && ref.current) {
Expand Down Expand Up @@ -220,6 +212,7 @@ const RepoEntry = ({
branch={branch}
focusedIndex={focusedIndex}
index={`${index}-${sii}`}
isLeftSidebarFocused={isLeftSidebarFocused}
/>
))}
</div>
Expand Down
Loading

0 comments on commit 714a37d

Please sign in to comment.