From 7c9ce6c98b255991ec6e6231a650a805c9ce8edf Mon Sep 17 00:00:00 2001 From: SuperTurk Date: Mon, 16 Oct 2023 11:43:29 +0200 Subject: [PATCH 1/5] fix: Improve UX for mobile user --- .../src/components/organisms/chat/index.tsx | 18 ++++--- .../sidebar/OpenChatHistoryButton.tsx | 48 +++++++++++++++++++ .../conversationsHistory/sidebar/index.tsx | 41 ++++++---------- frontend/src/components/organisms/header.tsx | 18 +++---- frontend/src/pages/Page.tsx | 2 + frontend/src/state/settings.ts | 2 + 6 files changed, 88 insertions(+), 41 deletions(-) create mode 100644 frontend/src/components/organisms/conversationsHistory/sidebar/OpenChatHistoryButton.tsx diff --git a/frontend/src/components/organisms/chat/index.tsx b/frontend/src/components/organisms/chat/index.tsx index 3ebe2af49b..034620c438 100644 --- a/frontend/src/components/organisms/chat/index.tsx +++ b/frontend/src/components/organisms/chat/index.tsx @@ -157,16 +157,22 @@ const Chat = () => { ) : null} - - {error && ( - - Could not reach the server. - + + + Could not reach the server. + + )} - {!messages.length && pSettings?.ui.show_readme_as_default ? ( ) : ( diff --git a/frontend/src/components/organisms/conversationsHistory/sidebar/OpenChatHistoryButton.tsx b/frontend/src/components/organisms/conversationsHistory/sidebar/OpenChatHistoryButton.tsx new file mode 100644 index 0000000000..6fdc0ef725 --- /dev/null +++ b/frontend/src/components/organisms/conversationsHistory/sidebar/OpenChatHistoryButton.tsx @@ -0,0 +1,48 @@ +import { useRecoilState } from 'recoil'; + +import KeyboardDoubleArrowRightIcon from '@mui/icons-material/KeyboardDoubleArrowRight'; +import Box from '@mui/material/Box'; +import IconButton from '@mui/material/IconButton'; + +import { settingsState } from 'state/settings'; + +const OpenChatHistoryButton = ({ mode }: { mode: 'mobile' | 'desktop' }) => { + const [settings, setSettings] = useRecoilState(settingsState); + const isDesktop = mode === 'desktop'; + + return !settings.isChatHistoryOpen ? ( + + theme.palette.background.paper + }} + onClick={() => + setSettings((prev) => ({ + ...prev, + isChatHistoryOpen: true + })) + } + > + + + + ) : null; +}; + +export default OpenChatHistoryButton; diff --git a/frontend/src/components/organisms/conversationsHistory/sidebar/index.tsx b/frontend/src/components/organisms/conversationsHistory/sidebar/index.tsx index fed44e0149..9b13775849 100644 --- a/frontend/src/components/organisms/conversationsHistory/sidebar/index.tsx +++ b/frontend/src/components/organisms/conversationsHistory/sidebar/index.tsx @@ -4,8 +4,6 @@ import { useEffect, useRef, useState } from 'react'; import { useRecoilState, useRecoilValue } from 'recoil'; import KeyboardDoubleArrowLeftIcon from '@mui/icons-material/KeyboardDoubleArrowLeft'; -import KeyboardDoubleArrowRightIcon from '@mui/icons-material/KeyboardDoubleArrowRight'; -import Box from '@mui/material/Box'; import Drawer from '@mui/material/Drawer'; import IconButton from '@mui/material/IconButton'; import Stack from '@mui/material/Stack'; @@ -20,6 +18,7 @@ import { conversationsHistoryState } from 'state/conversations'; import { projectSettingsState } from 'state/project'; +import { settingsState } from 'state/settings'; import { accessTokenState } from 'state/user'; import { ConversationsHistoryList } from './ConversationsHistoryList'; @@ -31,15 +30,15 @@ const BATCH_SIZE = 20; let _scrollTop = 0; const _ConversationsHistorySidebar = () => { - const isMobile = useMediaQuery('(max-width:800px)'); + const isMobile = useMediaQuery('(max-width:66rem)'); const [conversations, setConversations] = useRecoilState( conversationsHistoryState ); const accessToken = useRecoilValue(accessTokenState); const filters = useRecoilValue(conversationsFiltersState); + const [settings, setSettings] = useRecoilState(settingsState); - const [open, setOpen] = useState(true); const [shouldLoadMore, setShouldLoadMore] = useState(false); const [error, setError] = useState(undefined); const [prevFilters, setPrevFilters] = @@ -98,10 +97,17 @@ const _ConversationsHistorySidebar = () => { } }; + const setChatHistoryOpen = (open: boolean) => + setSettings((prev) => ({ ...prev, isChatHistoryOpen: open })); + useEffect(() => { if (ref.current) { ref.current.scrollTop = _scrollTop; } + + if (isMobile) { + setChatHistoryOpen(false); + } }, []); useEffect(() => { @@ -135,7 +141,7 @@ const _ConversationsHistorySidebar = () => { { onScroll: handleScroll }} sx={{ - width: open ? DRAWER_WIDTH : 0, + width: settings.isChatHistoryOpen ? DRAWER_WIDTH : 0, '& .MuiDrawer-paper': { position: 'inherit', gap: 1, @@ -171,8 +177,8 @@ const _ConversationsHistorySidebar = () => { > Chat History - setOpen(false)}> - + setChatHistoryOpen(false)}> + @@ -186,25 +192,6 @@ const _ConversationsHistorySidebar = () => { /> ) : null} - - theme.palette.background.paper - }} - onClick={() => setOpen(true)} - > - - - ); }; diff --git a/frontend/src/components/organisms/header.tsx b/frontend/src/components/organisms/header.tsx index 5d4a4d7a68..cc67007f3d 100644 --- a/frontend/src/components/organisms/header.tsx +++ b/frontend/src/components/organisms/header.tsx @@ -10,9 +10,7 @@ import { IconButton, Menu, Stack, - Theme, - Toolbar, - useTheme + Toolbar } from '@mui/material'; import useMediaQuery from '@mui/material/useMediaQuery'; @@ -23,8 +21,12 @@ import UserButton from 'components/atoms/buttons/userButton'; import { Logo } from 'components/atoms/logo'; import NewChatButton from 'components/molecules/newChatButton'; +import { useAuth } from 'hooks/auth'; + import { projectSettingsState } from 'state/project'; +import OpenChatHistoryButton from './conversationsHistory/sidebar/OpenChatHistoryButton'; + interface INavItem { to: string; label: string; @@ -63,7 +65,7 @@ interface NavProps { function Nav({ hasReadme }: NavProps) { const location = useLocation(); - const theme = useTheme(); + const { isAuthenticated } = useAuth(); const [open, setOpen] = useState(false); const ref = useRef(); @@ -73,8 +75,7 @@ function Nav({ hasReadme }: NavProps) { anchorEl = ref.current; } - const matches = useMediaQuery(theme.breakpoints.down('md')); - + const matches = useMediaQuery('(max-width: 66rem)'); const tabs = [{ to: '/', label: 'Chat' }]; if (hasReadme) { @@ -105,6 +106,7 @@ function Nav({ hasReadme }: NavProps) { > + {isAuthenticated ? : null} theme.breakpoints.down('md')); + const matches = useMediaQuery('(max-width: 66rem)'); return ( @@ -153,7 +155,7 @@ export default function Header() { borderBottomColor: (theme) => theme.palette.divider }} > - + {!matches ? : null}