Skip to content

Commit

Permalink
fix scroll bottom button flickering (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
willydouhard authored Jan 7, 2024
1 parent 1981d2a commit 5ee2f7e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
26 changes: 26 additions & 0 deletions frontend/src/components/atoms/buttons/scrollDownButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import ExpandCircleDown from '@mui/icons-material/ExpandCircleDown';
import IconButton from '@mui/material/IconButton';

interface Props {
onClick?: () => void;
}

export default function ScrollDownButton({ onClick }: Props) {
return (
<IconButton
sx={{
width: 'fit-content',
margin: 'auto',
position: 'absolute',
zIndex: 1,
transform: 'translateY(-100%)',
top: 0,
left: 0,
right: 0
}}
onClick={onClick}
>
<ExpandCircleDown fontSize="large" />
</IconButton>
);
}
1 change: 1 addition & 0 deletions frontend/src/components/organisms/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ const Chat = () => {
fileSpec={fileSpec}
onFileUpload={onFileUpload}
onFileUploadError={onFileUploadError}
autoScroll={autoScroll}
setAutoScroll={setAutoScroll}
projectSettings={projectSettings}
/>
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/components/organisms/chat/inputBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Box } from '@mui/material';

import { FileSpec, IStep, useChatInteract } from '@chainlit/react-client';

import ScrollDownButton from 'components/atoms/buttons/scrollDownButton';

import { IAttachment } from 'state/chat';
import { IProjectSettings } from 'state/project';
import { inputHistoryState } from 'state/userInputHistory';
Expand All @@ -19,6 +21,7 @@ interface Props {
onFileUpload: (payload: File[]) => void;
onFileUploadError: (error: string) => void;
setAutoScroll: (autoScroll: boolean) => void;
autoScroll?: boolean;
projectSettings?: IProjectSettings;
}

Expand All @@ -28,6 +31,7 @@ const InputBox = memo(
onFileUpload,
onFileUploadError,
setAutoScroll,
autoScroll,
projectSettings
}: Props) => {
const setInputHistory = useSetRecoilState(inputHistoryState);
Expand Down Expand Up @@ -94,6 +98,7 @@ const InputBox = memo(
return (
<Box
display="flex"
position="relative"
flexDirection="column"
gap={1}
p={2}
Expand All @@ -105,6 +110,9 @@ const InputBox = memo(
justifyContent: 'center'
}}
>
{!autoScroll ? (
<ScrollDownButton onClick={() => setAutoScroll(true)} />
) : null}
<Box>
<Input
fileSpec={fileSpec}
Expand Down
15 changes: 0 additions & 15 deletions libs/react-components/src/messages/MessageContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { MessageContext, defaultMessageContext } from 'contexts/MessageContext';
import { memo, useEffect, useRef } from 'react';

import ExpandCircleDown from '@mui/icons-material/ExpandCircleDown';
import Box from '@mui/material/Box';
import IconButton from '@mui/material/IconButton';

import type { IAction, IMessageElement, IStep } from 'client-types/';
import { IMessageContext } from 'src/types/messageContext';
Expand Down Expand Up @@ -64,19 +62,6 @@ const MessageContainer = memo(
elements={elements}
actions={actions}
/>
{!autoScroll ? (
<IconButton
sx={{
width: 'fit-content',
margin: 'auto',
position: 'sticky',
bottom: 0
}}
onClick={() => setAutoScroll && setAutoScroll(true)}
>
<ExpandCircleDown fontSize="large" />
</IconButton>
) : null}
</Box>
</MessageContext.Provider>
);
Expand Down

0 comments on commit 5ee2f7e

Please sign in to comment.