Skip to content

Commit

Permalink
✨ feat: 统一聊天模式和视频模式的输入方式
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmclin2 committed Apr 21, 2024
1 parent 9b5bc5c commit 918816a
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 102 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"immer": "^10.0.4",
"js-tiktoken": "^1.0.10",
"lodash-es": "^4.17.21",
"lucide-react": "^0.294.0",
"lucide-react": "^0.308.0",
"mmd-parser": "^1.0.4",
"next": "^14.1.4",
"next-pwa": "^5.6.0",
Expand Down
23 changes: 0 additions & 23 deletions src/app/chat/ChatBot/index.tsx

This file was deleted.

12 changes: 0 additions & 12 deletions src/app/chat/ChatBot/style.ts

This file was deleted.

35 changes: 0 additions & 35 deletions src/app/chat/VirtualIdol/index.tsx

This file was deleted.

20 changes: 16 additions & 4 deletions src/app/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,34 @@
import React, { memo } from 'react';
import { Flexbox } from 'react-layout-kit';

import ChatBot from '@/app/chat/ChatBot';
import VirtualIdol from '@/app/chat/VirtualIdol';
import AgentViewer from '@/features/AgentViewer';
import ChatDialog from '@/features/ChatDialog';
import ChatHeader from '@/features/ChatHeader';
import ChatInfo from '@/features/ChatInfo';
import MessageInput from '@/features/ChatInput/MessageInput';
import ChatList from '@/features/ChatList';
import SessionList from '@/features/SessionList';
import { useSessionStore } from '@/store/session';

import { useStyles } from './style';

const Chat = () => {
const viewerMode = useSessionStore((s) => s.viewerMode);
const [viewerMode] = useSessionStore((s) => [s.viewerMode]);
const { styles } = useStyles();

return (
<Flexbox flex={1} height={'100%'} width={'100%'} horizontal>
<SessionList />
<Flexbox height={'100%'} width={'100%'}>
<ChatHeader />
{viewerMode ? <VirtualIdol /> : <ChatBot />}
<Flexbox flex={1} style={{ overflow: 'hidden', position: 'relative' }}>
{viewerMode === true ? <AgentViewer /> : <ChatList />}
<Flexbox style={{}} align={'center'} width={'100%'} className={styles.docker}>
<MessageInput />
<div className={styles.alert}>请谨记:智能体所说的一切都是由 AI 生成的</div>
</Flexbox>
</Flexbox>
<ChatDialog />
</Flexbox>
<ChatInfo />
</Flexbox>
Expand Down
9 changes: 6 additions & 3 deletions src/app/chat/VirtualIdol/style.ts → src/app/chat/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import { createStyles } from 'antd-style';

export const useStyles = createStyles(({ css, token }) => ({
docker: css`
display: inline-flex;
flex-direction: column;
align-items: center;
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
max-width: 42vw;
padding: 8px 12px;
`,
alert: css`
Expand Down
4 changes: 2 additions & 2 deletions src/features/Actions/Edit.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActionIcon } from '@lobehub/ui';
import { Edit2 } from 'lucide-react';
import { SquarePen } from 'lucide-react';

import { useConfigStore } from '@/store/config';

Expand All @@ -8,7 +8,7 @@ export default () => {

return (
<ActionIcon
icon={Edit2}
icon={SquarePen}
onClick={() => {
openPanel('role');
}}
Expand Down
29 changes: 29 additions & 0 deletions src/features/Actions/Video.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ActionIcon } from '@lobehub/ui';
import { Video, VideoOff } from 'lucide-react';

import { useSessionStore } from '@/store/session';

export default () => {
const { viewerMode, setViewerMode } = useSessionStore((s) => ({
setViewerMode: s.setViewerMode,
viewerMode: s.viewerMode,
}));

return viewerMode ? (
<ActionIcon
icon={VideoOff}
onClick={() => {
setViewerMode(false);
}}
title={'关闭视频通话'}
/>
) : (
<ActionIcon
icon={Video}
onClick={() => {
setViewerMode(true);
}}
title={'视频通话'}
/>
);
};
2 changes: 0 additions & 2 deletions src/features/ChatInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import AgentInfo from '@/components/AgentInfo';
import Dance from '@/features/Actions/Dance';
import Edit from '@/features/Actions/Edit';
import Log from '@/features/Actions/Log';
import ViewerMode from '@/features/Actions/ViewerMode';
import Voice from '@/features/Actions/Voice';
import { sessionSelectors, useSessionStore } from '@/store/session';

Expand Down Expand Up @@ -44,7 +43,6 @@ const Header = () => {
]}
agent={currentAgent}
/>
<ViewerMode key={'viewer'} />,
</DraggablePanel>
);
};
Expand Down
33 changes: 13 additions & 20 deletions src/features/ChatInput/MessageInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
import { Avatar, Input } from '@lobehub/ui';
import { Button, Space } from 'antd';
import { createStyles } from 'antd-style';
import { SendOutlined } from '@ant-design/icons';
import { Input } from '@lobehub/ui';
import { Button } from 'antd';
import { InputRef } from 'antd/es/input/Input';
import { memo, useRef } from 'react';
import React, { memo, useRef } from 'react';
import { Flexbox } from 'react-layout-kit';

import { DEFAULT_USER_AVATAR } from '@/constants/common';
import Record from '@/features/Actions/Record';
import Video from '@/features/Actions/Video';
import useChatInput from '@/hooks/useSendMessage';
import { useSessionStore } from '@/store/session';
import { isCommandPressed } from '@/utils/keyboard';

const useStyles = createStyles(({ css }) => {
return {
textarea: css`
width: 400px;
`,
};
});

const InputArea = memo(() => {
const { styles } = useStyles();
const ref = useRef<InputRef>(null);
const isChineseInput = useRef(false);
const onSend = useChatInput();
Expand All @@ -31,11 +23,11 @@ const InputArea = memo(() => {
]);

return (
<Space size={4}>
<Avatar avatar={DEFAULT_USER_AVATAR} />
<Flexbox height={'100%'} width={'100%'} horizontal>
<Record />
<Input
width={'100%'}
autoFocus
className={styles.textarea}
onBlur={(e) => {
setMessageInput?.(e.target.value);
}}
Expand Down Expand Up @@ -69,12 +61,13 @@ const InputArea = memo(() => {
if (loading) return;
onSend();
}}
icon={<SendOutlined />}
type="primary"
>
发送
{/*发送*/}
</Button>
<Record />
</Space>
<Video />
</Flexbox>
);
});

Expand Down

0 comments on commit 918816a

Please sign in to comment.