Skip to content

Commit

Permalink
🐛 fix: Fix ActionBar props and regenerate btn with error message (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
canisminor1990 committed Oct 17, 2023
1 parent 5c09420 commit 246e8fd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import { Flexbox } from 'react-layout-kit';

import { useSessionStore } from '@/store/session';
import { agentSelectors } from '@/store/session/slices/agentConfig';
import { currentFunctionCallProps } from '@/store/session/slices/chat/selectors/chat';
import { chatSelectors } from '@/store/session/slices/chat/selectors';
import { isFunctionMessage } from '@/utils/message';

import FunctionCall from '../Plugins/FunctionCall';
import { DefautMessage } from './Default';
import { SystemActionsBar } from './System';

const useStyles = createStyles(({ css }) => ({
container: css`
Expand All @@ -34,7 +33,7 @@ const useStyles = createStyles(({ css }) => ({

export const AssistantMessage: RenderMessage = memo(
({ id, plugin, function_call, content, ...props }) => {
const genFunctionCallProps = useSessionStore(currentFunctionCallProps);
const genFunctionCallProps = useSessionStore(chatSelectors.currentFunctionCallProps);

if (!isFunctionMessage(content)) return <DefautMessage content={content} id={id} {...props} />;

Expand Down Expand Up @@ -65,16 +64,15 @@ export const AssistantMessageExtra: RenderMessageExtra = memo(({ extra, function
);
});

export const AssistantActionsBar: RenderAction = memo(({ text, error, id, ...props }) => {
export const AssistantActionsBar: RenderAction = memo(({ text, error, id, onActionClick }) => {
const { regenerate, edit, copy, divider, del } = useChatListActionsBar(text);
if (id === 'default') return;
if (error) return <SystemActionsBar id={id} text={text} {...props} />;
return (
<ActionIconGroup
dropdownMenu={[edit, copy, regenerate, divider, del]}
items={[regenerate, copy]}
dropdownMenu={error ? [regenerate, divider, del] : [edit, copy, regenerate, divider, del]}
items={[regenerate]}
onActionClick={onActionClick}
type="ghost"
{...props}
/>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { memo } from 'react';
import { Flexbox } from 'react-layout-kit';

import { useSessionStore } from '@/store/session';
import { currentFunctionCallProps } from '@/store/session/slices/chat/selectors/chat';
import { chatSelectors } from '@/store/session/selectors';

import FunctionCall from '../Plugins/FunctionCall';
import PluginMessage from '../Plugins/PluginMessage';

export const FunctionMessage: RenderMessage = memo(
({ id, content, plugin, function_call, ...props }) => {
const genFunctionCallProps = useSessionStore(currentFunctionCallProps);
const genFunctionCallProps = useSessionStore(chatSelectors.currentFunctionCallProps);
const fcProps = genFunctionCallProps({ content, function_call, id, plugin });

return (
Expand All @@ -29,14 +29,14 @@ export const FunctionMessage: RenderMessage = memo(
},
);

export const FunctionActionsBar: RenderAction = memo(({ text, ...props }) => {
export const FunctionActionsBar: RenderAction = memo(({ text, onActionClick }) => {
const { regenerate, divider, del } = useChatListActionsBar(text);
return (
<ActionIconGroup
dropdownMenu={[regenerate, divider, del]}
items={[regenerate]}
onActionClick={onActionClick}
type="ghost"
{...props}
/>
);
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ActionIconGroup, RenderAction, useChatListActionsBar } from '@lobehub/ui';
import { memo } from 'react';

export const SystemActionsBar: RenderAction = memo(({ text, ...props }) => {
export const SystemActionsBar: RenderAction = memo(({ text, onActionClick }) => {
const { del } = useChatListActionsBar(text);
return <ActionIconGroup dropdownMenu={[del]} items={[]} type="ghost" {...props} />;
return (
<ActionIconGroup dropdownMenu={[del]} items={[]} onActionClick={onActionClick} type="ghost" />
);
});
4 changes: 2 additions & 2 deletions src/app/chat/features/Conversation/ChatList/Messages/User.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ActionIconGroup, RenderAction, useChatListActionsBar } from '@lobehub/ui';
import { memo } from 'react';

export const UserActionsBar: RenderAction = memo(({ text, ...props }) => {
export const UserActionsBar: RenderAction = memo(({ text, onActionClick }) => {
const { regenerate, edit, copy, divider, del } = useChatListActionsBar(text);
return (
<ActionIconGroup
dropdownMenu={[edit, copy, regenerate, divider, del]}
items={[regenerate, edit]}
onActionClick={onActionClick}
type="ghost"
{...props}
/>
);
});
2 changes: 2 additions & 0 deletions src/store/session/slices/chat/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
currentChats,
currentChatsWithGuideMessage,
currentChatsWithHistoryConfig,
currentFunctionCallProps,
getChatsById,
} from './chat';
import { currentTopics, getTopicMessages } from './topic';
Expand All @@ -12,6 +13,7 @@ export const chatSelectors = {
currentChats,
currentChatsWithGuideMessage,
currentChatsWithHistoryConfig,
currentFunctionCallProps,
getChatsById,
};

Expand Down

0 comments on commit 246e8fd

Please sign in to comment.