Skip to content

Commit beee02a

Browse files
committed
feat: [AIChatInput] The newly added keepSkillAfterSend API allows users to set whether to delete the skill upon sending
1 parent efe11d5 commit beee02a

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

packages/semi-ui/aiChatInput/_story/aiChatInput.stories.jsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,4 +639,38 @@ export const AddPasteRule = () => {
639639
{/* <Button onClick={onButtonClick2}>点我设置结果</Button> */}
640640
</>
641641
);
642+
}
643+
644+
export const KeepSkill = () => {
645+
const ref = useRef();
646+
const [generating, setGenerating] = useState(false);
647+
648+
const onContentChange = useCallback((content) => {
649+
console.log('onContentChange', content);
650+
}, []);
651+
652+
const toggleGenerate = useCallback((props) => {
653+
setGenerating(value => !value);
654+
}, []);
655+
656+
return (<>
657+
<AIChatInput
658+
ref={ref}
659+
generating={generating}
660+
keepSkillAfterSend
661+
defaultContent={`<skill-slot data-label="帮我写作" data-value="writing" data-template=true></skill-slot>帮我完成...`}
662+
placeholder={'输入内容或者上传内容'}
663+
uploadProps={uploadProps}
664+
onContentChange={onContentChange}
665+
onMessageSend={toggleGenerate}
666+
onStopGenerate={toggleGenerate}
667+
style={outerStyle}
668+
/>
669+
<Button onClick={() => {
670+
const html = ref.current.editor.getHTML();
671+
const json = ref.current.editor.getJSON();
672+
console.log('html', html);
673+
console.log('json', json);
674+
}}>点击获取</Button>
675+
</>);
642676
}

packages/semi-ui/aiChatInput/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class AIChatInput extends BaseComponent<AIChatInputProps, AIChatInputState> {
5454
dropdownMatchTriggerWidth: true,
5555
round: true,
5656
topSlotPosition: 'top',
57+
keepSkillAfterSend: false,
5758
}
5859

5960
constructor(props: AIChatInputProps) {
@@ -203,14 +204,14 @@ class AIChatInput extends BaseComponent<AIChatInputProps, AIChatInputState> {
203204
}
204205

205206
componentDidUpdate(prevProps: Readonly<AIChatInputProps>): void {
206-
const { suggestions } = this.props;
207+
const { suggestions, keepSkillAfterSend } = this.props;
207208
if (!isEqual(suggestions, prevProps.suggestions)) {
208209
const newVisible = (suggestions && suggestions.length > 0) ? true : false;
209210
newVisible ? this.foundation.showSuggestionPanel() :
210211
this.foundation.hideSuggestionPanel();
211212
}
212213
if (this.props.generating && (this.props.generating !== prevProps.generating)) {
213-
this.adapter.clearContent();
214+
keepSkillAfterSend ? this.setContentWhileSaveTool('') : this.adapter.clearContent();
214215
this.adapter.clearAttachments();
215216
}
216217
}

packages/semi-ui/aiChatInput/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface AIChatInputState {
2323

2424
export interface AIChatInputProps {
2525
dropdownMatchTriggerWidth?: boolean;
26+
keepSkillAfterSend: boolean;
2627
className?: string;
2728
style?: React.CSSProperties;
2829
// Rich text editor related

0 commit comments

Comments
 (0)