Skip to content

Commit 30b2639

Browse files
authored
💄 style(chat): auto send message from URL (lobehub#6497)
* ✨ feat(chat): auto send message from URL * introduce MessageFromUrl component
1 parent 81867c4 commit 30b2639

File tree

2 files changed

+76
-39
lines changed

2 files changed

+76
-39
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use client';
2+
3+
import { useSearchParams } from 'next/navigation';
4+
import { useEffect } from 'react';
5+
6+
import { useSendMessage } from '@/features/ChatInput/useSend';
7+
import { useChatStore } from '@/store/chat';
8+
9+
const MessageFromUrl = () => {
10+
const updateInputMessage = useChatStore((s) => s.updateInputMessage);
11+
const { send: sendMessage } = useSendMessage();
12+
const searchParams = useSearchParams();
13+
14+
useEffect(() => {
15+
const message = searchParams.get('message');
16+
if (message) {
17+
// Remove message from URL
18+
const params = new URLSearchParams(searchParams.toString());
19+
params.delete('message');
20+
const newUrl = `${window.location.pathname}?${params.toString()}`;
21+
window.history.replaceState({}, '', newUrl);
22+
23+
updateInputMessage(message);
24+
sendMessage();
25+
}
26+
}, [searchParams, updateInputMessage, sendMessage]);
27+
28+
return null;
29+
};
30+
31+
export default MessageFromUrl;

Diff for: ‎src/app/[variants]/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/Footer/index.tsx

+45-39
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Button, Space } from 'antd';
22
import { createStyles } from 'antd-style';
33
import { rgba } from 'polished';
4-
import { memo, useEffect, useState } from 'react';
4+
import { Suspense, memo, useEffect, useState } from 'react';
55
import { useTranslation } from 'react-i18next';
66
import { Flexbox } from 'react-layout-kit';
77

@@ -13,6 +13,7 @@ import { useChatStore } from '@/store/chat';
1313
import { chatSelectors } from '@/store/chat/selectors';
1414
import { isMacOS } from '@/utils/platform';
1515

16+
import MessageFromUrl from './MessageFromUrl';
1617
import SendMore from './SendMore';
1718
import ShortcutHint from './ShortcutHint';
1819

@@ -67,49 +68,54 @@ const Footer = memo<FooterProps>(({ onExpandChange, expand }) => {
6768
}, [setIsMac]);
6869

6970
return (
70-
<Flexbox
71-
align={'end'}
72-
className={styles.overrideAntdIcon}
73-
distribution={'space-between'}
74-
flex={'none'}
75-
gap={8}
76-
horizontal
77-
padding={'0 24px'}
78-
>
79-
<Flexbox align={'center'} gap={8} horizontal style={{ overflow: 'hidden' }}>
80-
{expand && <LocalFiles />}
81-
</Flexbox>
82-
<Flexbox align={'center'} flex={'none'} gap={8} horizontal>
83-
<ShortcutHint />
84-
<SaveTopic />
85-
<Flexbox style={{ minWidth: 92 }}>
86-
{isAIGenerating ? (
87-
<Button
88-
className={styles.loadingButton}
89-
icon={<StopLoadingIcon />}
90-
onClick={stopGenerateMessage}
91-
>
92-
{t('input.stop')}
93-
</Button>
94-
) : (
95-
<Space.Compact>
71+
<>
72+
<Suspense fallback={null}>
73+
<MessageFromUrl />
74+
</Suspense>
75+
<Flexbox
76+
align={'end'}
77+
className={styles.overrideAntdIcon}
78+
distribution={'space-between'}
79+
flex={'none'}
80+
gap={8}
81+
horizontal
82+
padding={'0 24px'}
83+
>
84+
<Flexbox align={'center'} gap={8} horizontal style={{ overflow: 'hidden' }}>
85+
{expand && <LocalFiles />}
86+
</Flexbox>
87+
<Flexbox align={'center'} flex={'none'} gap={8} horizontal>
88+
<ShortcutHint />
89+
<SaveTopic />
90+
<Flexbox style={{ minWidth: 92 }}>
91+
{isAIGenerating ? (
9692
<Button
97-
disabled={!canSend}
98-
loading={!canSend}
99-
onClick={() => {
100-
sendMessage();
101-
onExpandChange?.(false);
102-
}}
103-
type={'primary'}
93+
className={styles.loadingButton}
94+
icon={<StopLoadingIcon />}
95+
onClick={stopGenerateMessage}
10496
>
105-
{t('input.send')}
97+
{t('input.stop')}
10698
</Button>
107-
<SendMore disabled={!canSend} isMac={isMac} />
108-
</Space.Compact>
109-
)}
99+
) : (
100+
<Space.Compact>
101+
<Button
102+
disabled={!canSend}
103+
loading={!canSend}
104+
onClick={() => {
105+
sendMessage();
106+
onExpandChange?.(false);
107+
}}
108+
type={'primary'}
109+
>
110+
{t('input.send')}
111+
</Button>
112+
<SendMore disabled={!canSend} isMac={isMac} />
113+
</Space.Compact>
114+
)}
115+
</Flexbox>
110116
</Flexbox>
111117
</Flexbox>
112-
</Flexbox>
118+
</>
113119
);
114120
});
115121

0 commit comments

Comments
 (0)