Refactor: Extract RegenerationButton and StopButton components in ChatPanel

Extracted the RegenerationButton and StopButton components from the chatPanel function in the ChatPanel/index.tsx file.
Replaced the previous inline implementation with the new RegenerationButton and StopButton components.
RegenerationButton and StopButton components handle the regeneration and stopping of message generation, respectively.
This commit is contained in:
Rankin Zheng 2023-06-05 18:35:21 +08:00
parent a835755439
commit d500fe63f1

View File

@ -686,6 +686,65 @@ const chatPanel = () => {
</Flex>);
});
const RegenerationButton = () => {
return (<Button
size='xs'
leftIcon={<IconRotateDot color='var(--vscode-button-foreground)' />}
sx={{
backgroundColor: 'var(--vscode-button-background)',
}}
styles={{
icon: {
color: 'var(--vscode-button-foreground)'
},
label: {
color: 'var(--vscode-button-foreground)',
fontSize: 'var(--vscode-editor-font-size)',
}
}}
variant="white"
onClick={() => {
messageUtil.sendMessage({
command: 'regeneration'
});
messageHandlers.pop();
setHasError(false);
setGenerating(true);
setResponsed(false);
setCurrentMessage('');
}}>
Regeneration
</Button>);
};
const StopButton = () => {
return (
<Button
size='xs'
leftIcon={<IconPlayerStop color='var(--vscode-button-foreground)' />}
sx={{
backgroundColor: 'var(--vscode-button-background)',
}}
styles={{
icon: {
color: 'var(--vscode-button-foreground)'
},
label: {
color: 'var(--vscode-button-foreground)',
fontSize: 'var(--vscode-editor-font-size)',
}
}}
variant="white"
onClick={() => {
messageUtil.sendMessage({
command: 'stopDevChat'
});
setGenerating(false);
}}>
Stop generating
</Button>);
};
return (
<Container
id='chat-container'
@ -716,62 +775,12 @@ const chatPanel = () => {
sx={{ position: 'absolute', bottom: 10, width: chatContainerRect.width }}>
{generating &&
<Center>
<Button
size='xs'
leftIcon={<IconPlayerStop color='var(--vscode-button-foreground)' />}
sx={{
backgroundColor: 'var(--vscode-button-background)',
}}
styles={{
icon: {
color: 'var(--vscode-button-foreground)'
},
label: {
color: 'var(--vscode-button-foreground)',
fontSize: 'var(--vscode-editor-font-size)',
}
}}
variant="white"
onClick={() => {
messageUtil.sendMessage({
command: 'stopDevChat'
});
setGenerating(false);
}}>
Stop generating
</Button>
<StopButton />
</Center>
}
{hasError &&
<Center>
<Button
size='xs'
leftIcon={<IconRotateDot color='var(--vscode-button-foreground)' />}
sx={{
backgroundColor: 'var(--vscode-button-background)',
}}
styles={{
icon: {
color: 'var(--vscode-button-foreground)'
},
label: {
color: 'var(--vscode-button-foreground)',
fontSize: 'var(--vscode-editor-font-size)',
}
}}
variant="white"
onClick={() => {
messageUtil.sendMessage({
command: 'regeneration'
});
messageHandlers.pop();
setHasError(false);
setGenerating(true);
setResponsed(false);
setCurrentMessage('');
}}>
Regeneration
</Button>
<RegenerationButton />
</Center>
}
{contexts && contexts.length > 0 &&