Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug/input-history] Add button for opening input history #1121

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions frontend/src/components/organisms/chat/history/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ import { useRecoilState } from 'recoil';
import { grey } from 'theme';

import AutoDelete from '@mui/icons-material/AutoDelete';
import { IconButton, Menu, MenuItem, Stack, Typography } from '@mui/material';
import HistoryIcon from '@mui/icons-material/History';
import {
IconButton,
Menu,
MenuItem,
Stack,
Theme,
Typography,
useMediaQuery
} from '@mui/material';

import { UserInput } from '@chainlit/react-client';

Expand Down Expand Up @@ -62,6 +71,10 @@ export default function InputHistoryButton({ onClick }: Props) {
const ref = useRef<any>();
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);

const size = useMediaQuery<Theme>((theme) => theme.breakpoints.down('sm'))
? 'small'
: 'medium';

if (inputHistory.open && !anchorEl) {
if (ref.current) {
setAnchorEl(ref.current);
Expand All @@ -71,6 +84,13 @@ export default function InputHistoryButton({ onClick }: Props) {
const toggleChatHistoryMenu = (open: boolean) =>
setInputHistory((old) => ({ ...old, open }));

const handleHistoryButtonClick = (
event: React.MouseEvent<HTMLButtonElement>
) => {
setAnchorEl(event.currentTarget);
toggleChatHistoryMenu(true);
};

const header = (
// @ts-ignore
<Stack
Expand Down Expand Up @@ -227,5 +247,16 @@ export default function InputHistoryButton({ onClick }: Props) {
</Menu>
) : null;

return <div ref={ref}>{menu}</div>;
return (
<div ref={ref}>
<IconButton
color="inherit"
size={size}
onClick={handleHistoryButtonClick}
>
<HistoryIcon />
</IconButton>
{menu}
</div>
);
}
Loading