Skip to content

Commit

Permalink
Merge pull request #32 from lobehub/feat/add-chat-router
Browse files Browse the repository at this point in the history
fix: 修复聊天框样式问题
  • Loading branch information
rdmclin2 authored Apr 22, 2024
2 parents a5e4ac6 + 10cece9 commit 83f3a49
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 65 deletions.
4 changes: 2 additions & 2 deletions src/app/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const Chat = () => {
<Flexbox flex={1} style={{ overflow: 'hidden', position: 'relative' }}>
{viewerMode === true ? <AgentViewer /> : <ChatList />}
</Flexbox>
<Flexbox align={'center'} width={'100%'} className={styles.docker}>
<MessageInput />
<Flexbox align={'center'} width={'100%'} className={styles.docker} justify={'center'}>
<MessageInput className={styles.input} />
<div className={styles.alert}>请谨记:智能体所说的一切都是由 AI 生成的</div>
</Flexbox>
</Flexbox>
Expand Down
15 changes: 8 additions & 7 deletions src/app/chat/style.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { createStyles } from 'antd-style';

import { CHAT_INPUT_HEIGHT, CHAT_INPUT_WIDTH } from '@/constants/common';

export const useStyles = createStyles(({ css, token }) => ({
docker: css`
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
max-width: 42vw;
padding: 8px 12px;
height: ${CHAT_INPUT_HEIGHT}px;
background-color: rgba(${token.colorBgLayout}, 0.8);
backdrop-filter: saturate(180%) blur(2px);
`,
input: css`
width: ${CHAT_INPUT_WIDTH};
`,
alert: css`
padding: ${token.marginXS}px;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Panel/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const useStyles = createStyles(({ css, token }) => ({
width: 900px;
background-color: ${token.colorBgMask};
background-color: rgba(${token.colorBgLayout}, 0.8);
backdrop-filter: saturate(180%) blur(10px);
border: 1px solid ${token.colorBorder};
border-radius: ${token.borderRadius}px;
Expand Down
6 changes: 6 additions & 0 deletions src/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ export const INITIAL_Z_INDEX = 10;
export const CHAT_TEXTAREA_MAX_HEIGHT = 570;
export const CHAT_TEXTAREA_HEIGHT = 200;

export const CHAT_INPUT_HEIGHT = 90;

export const HEADER_HEIGHT = 64;

export const CHAT_HEADER_HEIGHT = 64;

export const CHAT_INPUT_WIDTH = '42vw';

export const DEFAULT_USER_AVATAR = '😀';

export const LIST_GRID_WIDTH = 108;
Expand Down
21 changes: 7 additions & 14 deletions src/features/Actions/PlayControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,20 @@ interface Props {
export default (props: Props) => {
const { style, className } = props;
const { styles } = useStyles();
const [isPlaying, togglePlayPause] = useDanceStore((s) => [s.isPlaying, s.togglePlayPause]);
const [isPlaying, togglePlayPause, playlist] = useDanceStore((s) => [
s.isPlaying,
s.togglePlayPause,
s.playlist,
]);

// return (
// <GradientButton
// className={classNames(isPlaying ? styles.spin : '', className)}
// glow={isPlaying}
// onClick={togglePlayPause}
// shape="circle"
// >
// <TikTokOutlined style={{ fontSize: 22 }} />
// </GradientButton>
// );

return (
return playlist.length ? (
<ActionIcon
className={classNames(isPlaying ? styles.spin : '', className)}
style={style}
onClick={togglePlayPause}
icon={Music2}
/>
);
) : null;

// return (
// <Avatar
Expand Down
2 changes: 1 addition & 1 deletion src/features/AgentViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function AgentViewer() {
<ChatDialog className={styles.dialog} />
<ToolBar className={styles.toolbar} />
{loading ? <PageLoading title={'模型加载中,请稍后...'} /> : null}
<canvas ref={canvasRef}></canvas>
<canvas ref={canvasRef} height={'100%'} width={'100%'}></canvas>
</div>
);
}
Expand Down
17 changes: 9 additions & 8 deletions src/features/AgentViewer/style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { createStyles } from 'antd-style';

import {
CHAT_HEADER_HEIGHT,
CHAT_INPUT_HEIGHT,
CHAT_INPUT_WIDTH,
HEADER_HEIGHT,
} from '@/constants/common';

export const useStyles = createStyles(({ css, token }) => ({
toolbar: css`
position: absolute;
Expand All @@ -15,16 +22,10 @@ export const useStyles = createStyles(({ css, token }) => ({
display: flex;
min-width: 480px;
width: ${CHAT_INPUT_WIDTH};
`,
// controller: css`
// position: absolute;
// right: ${token.paddingMD}px;
// top: ${token.paddingMD}px;
// `,
viewer: css`
position: relative;
width: 100%;
height: 100%;
height: calc(100vh - ${HEADER_HEIGHT}px - ${CHAT_HEADER_HEIGHT}px - ${CHAT_INPUT_HEIGHT}px);
`,
}));
7 changes: 6 additions & 1 deletion src/features/AudioPlayer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ function Player(props: PlayerProps) {
src={currentPlay?.audio}
/>
<div className={styles.player}>
<Avatar shape="circle" size={48} src={currentPlay?.cover} />
<Avatar
shape="circle"
size={48}
src={currentPlay?.cover}
className={isPlaying ? styles.spin : ''}
/>
<div className={styles.content}>
<Duration currentProgress={currentProgress} duration={duration} />
<div className={styles.controller}>
Expand Down
13 changes: 13 additions & 0 deletions src/features/AudioPlayer/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ const useStyles = createStyles(({ token, css }) => ({
display: flex;
align-items: center;
`,
spin: css`
@keyframes rotate-animation {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
animation: rotate-animation 20s linear infinite;
`,
}));

export { useStyles };
5 changes: 3 additions & 2 deletions src/features/ChatHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Space } from 'antd';
import React from 'react';
import { Flexbox } from 'react-layout-kit';

import AgentMeta from '@/components/agent/AgentMeta';
import PlayControl from '@/features/Actions/PlayControl';
Expand All @@ -14,14 +15,14 @@ const Header = () => {
const [currentAgent] = useSessionStore((s) => [sessionSelectors.currentAgent(s)]);

return (
<div className={styles.header}>
<Flexbox justify={'space-between'} horizontal align={'center'} className={styles.header}>
<AgentMeta meta={currentAgent?.meta} />
<Space>
<Voice key={'voice'} />
<Video key={'video'} />
<PlayControl key="play" />
</Space>
</div>
</Flexbox>
);
};

Expand Down
11 changes: 4 additions & 7 deletions src/features/ChatHeader/style.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { createStyles } from 'antd-style';

import { CHAT_HEADER_HEIGHT } from '@/constants/common';

const useStyles = createStyles(({ token, css }) => ({
header: css`
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding: 16px 8px;
height: ${CHAT_HEADER_HEIGHT}px;
padding: ${token.paddingSM}px;
border-bottom: 1px solid ${token.colorBorderSecondary};
`,
player: css`
Expand Down
10 changes: 8 additions & 2 deletions src/features/ChatInput/MessageInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ import useChatInput from '@/hooks/useSendMessage';
import { useSessionStore } from '@/store/session';
import { isCommandPressed } from '@/utils/keyboard';

const InputArea = memo(() => {
interface InputAreaProps {
className?: string;
style?: React.CSSProperties;
}

const InputArea = memo((props: InputAreaProps) => {
const ref = useRef<InputRef>(null);
const isChineseInput = useRef(false);
const onSend = useChatInput();
const { className, style } = props;

const [loading, messageInput, setMessageInput] = useSessionStore((s) => [
!!s.chatLoadingId,
Expand All @@ -22,7 +28,7 @@ const InputArea = memo(() => {
]);

return (
<Flexbox height={'100%'} width={'100%'} horizontal gap={4}>
<Flexbox width={'100%'} horizontal gap={4} className={className} style={style}>
<Record />
<Input
width={'100%'}
Expand Down
30 changes: 17 additions & 13 deletions src/features/SessionList/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,24 @@ const Header = memo((props: HeaderProps) => {
const openPanel = useConfigStore((s) => s.openPanel);

return (
<div className={styles.header}>
<Flexbox flex={1} style={{ marginRight: 4 }}>
<SearchBar
enableShortKey
onChange={(e) => {
if (onChange) onChange(e.target.value);
}}
placeholder="搜索"
shortKey="f"
value={value}
/>
</Flexbox>
<Flexbox
justify={'space-between'}
horizontal
align={'center'}
className={styles.header}
gap={4}
>
<SearchBar
enableShortKey
onChange={(e) => {
if (onChange) onChange(e.target.value);
}}
placeholder="搜索"
shortKey="f"
value={value}
/>
<ActionIcon icon={Plus} onClick={() => openPanel('agent')} title={'创建对话'} />
</div>
</Flexbox>
);
});

Expand Down
10 changes: 4 additions & 6 deletions src/features/SessionList/style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { createStyles } from 'antd-style';

import { HEADER_HEIGHT } from '@/constants/common';

export const useStyles = createStyles(({ css, token }) => ({
date: css`
font-size: 12px;
Expand All @@ -10,12 +12,8 @@ export const useStyles = createStyles(({ css, token }) => ({
text-align: center;
`,
header: css`
display: flex;
justify-content: space-between;
width: 100%;
padding: 16px 8px;
height: ${HEADER_HEIGHT}px;
padding: ${token.paddingSM}px;
border-bottom: 1px solid ${token.colorBorderSecondary};
`,

Expand Down
2 changes: 1 addition & 1 deletion src/store/session/initialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const initialState = {
localAgentList: [DEFAULT_AGENT],
messageInput: '',
sessionList: [defaultSession],
viewerMode: true,
viewerMode: false,
voiceOn: true,
};

Expand Down

0 comments on commit 83f3a49

Please sign in to comment.